Jump to content

Recommended Posts

Posted (edited)

Hi!

I am currently struggling with a weird problem when i try to add subclasses with _WinAPI_SetWindowSubclass to controls. Tested with AutoIt Version 3.3.14.5.

 

#include <MsgBoxConstants.au3>
#include <StaticConstants.au3>
#include <TreeViewConstants.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <WinAPIShellEx.au3>

OnAutoItExitRegister('OnAutoItExit')

Global $Inst = "Steps to reprocedere:"&@crlf & _
               "1. Select some text in the input 1 control box."&@crlf & _
               "2. Set focus to the 'ignore me' gui"&@crlf & _
               "3. Set the focus to an item in the treeview (You can already note, the focus is still on input1)"&@crlf & _
               "4. Type some text in input 2"&@crlf & _
               "5. Bugtime: Try editing text in input 1..you can´t even set the focus to the control. It´s still in input 2. Why ?!?"


Global $g_hForm = GUICreate('Strange stuff..',640,480)
GUICtrlCreateLabel($Inst, 10, 10, 600, 120)
Global $hInput = GUICtrlCreateInput("input 1", 10, 150, 280, 20)
Global $hInput2 = GUICtrlCreateInput("input 2", 10, 170, 280, 20)
Global $idTreeview = GUICtrlCreateTreeView(10, 200, 100, 150, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE)
Global $idGeneralitem = GUICtrlCreateTreeViewItem("General", $idTreeview)
Global $idDisplayitem = GUICtrlCreateTreeViewItem("Display", $idTreeview)


Global $g_hDll = DllCallbackRegister('_SubclassProc', 'lresult', 'hwnd;uint;wparam;lparam;uint_ptr;dword_ptr')
Global $g_pDll = DllCallbackGetPtr($g_hDll)

; Install window subclass callback
_WinAPI_SetWindowSubclass(GUICtrlGetHandle($hInput), $g_pDll, 1000, 0)
_WinAPI_SetWindowSubclass(GUICtrlGetHandle($hInput2), $g_pDll, 1001, 0)

GUISetState(@SW_SHOW,$g_hForm)


$hGUI2 = GUICreate("Ignore me", 300, 300,30,30)
GUICtrlCreateLabel('IGNORE ME...', 10, 10, 280, 20)
GUISetState(@SW_SHOW, $hGUI2)

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

Func _SubclassProc($hWnd, $iMsg, $wParam, $lParam, $iID, $pData)
    Return _WinAPI_DefSubclassProc($hWnd, $iMsg, $wParam, $lParam)
EndFunc   ;==>_SubclassProc

Func OnAutoItExit()
    _WinAPI_RemoveWindowSubclass(GUICtrlGetHandle($hInput), $g_pDll, 1000)
    _WinAPI_RemoveWindowSubclass(GUICtrlGetHandle($hInput2), $g_pDll, 1001)
    DllCallbackFree($g_hDll)
EndFunc   ;==>OnAutoItExit

 Steps to reprocedere:

  • Select some text in the input 1 control box
  • Set focus to the 'ignore me' gui
  • Set the focus to an item in the treeview (You can already note, the focus is still on input1)
  • Type some text in input 2
  • Bugtime: Try editing text in input 1..you can´t even set the focus to the control. It´s still in input 2. Why ?!?


Maybe someone has an idea to this..

As always, thanks in advance!

 

 

Edited by ISI360
Posted

ISI360, You can observe that if you click in the $g_hForm GUI before clicking the treeview item, it works.

I think the problem is more related to a complicated message flow (Windows messages, internal AutoIt message handling, additional messages related to subclassing and messages from two GUIs which, for one reason or another, is not properly controlled) than it's actually related to the subclassing technique itself.

You can implement the workaround in code this way:

#include <MsgBoxConstants.au3>
#include <StaticConstants.au3>
#include <TreeViewConstants.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <WinAPIShellEx.au3>

OnAutoItExitRegister('OnAutoItExit')

Global $Inst = "Steps to reprocedere:"&@crlf & _
               "1. Select some text in the input 1 control box."&@crlf & _
               "2. Set focus to the 'ignore me' gui"&@crlf & _
               "3. Set the focus to an item in the treeview (You can already note, the focus is still on input1)"&@crlf & _
               "4. Type some text in input 2"&@crlf & _
               "5. Bugtime: Try editing text in input 1..you can´t even set the focus to the control. It´s still in input 2. Why ?!?"


Global $g_hForm = GUICreate('Strange stuff..',640,480)
Global $idLabel = GUICtrlCreateLabel($Inst, 10, 10, 600, 120)
Global $hInput = GUICtrlCreateInput("input 1", 10, 150, 280, 20)
Global $hInput2 = GUICtrlCreateInput("input 2", 10, 170, 280, 20)
Global $idTreeview = GUICtrlCreateTreeView(10, 200, 100, 150, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE)
Global $idGeneralitem = GUICtrlCreateTreeViewItem("General", $idTreeview)
Global $idDisplayitem = GUICtrlCreateTreeViewItem("Display", $idTreeview)


Global $g_hDll = DllCallbackRegister('_SubclassProc', 'lresult', 'hwnd;uint;wparam;lparam;uint_ptr;dword_ptr')
Global $g_pDll = DllCallbackGetPtr($g_hDll)

; Install window subclass callback
_WinAPI_SetWindowSubclass(GUICtrlGetHandle($hInput), $g_pDll, 1000, 0)
_WinAPI_SetWindowSubclass(GUICtrlGetHandle($hInput2), $g_pDll, 1001, 0)

GUIRegisterMsg( $WM_ACTIVATE, "WM_ACTIVATE" )

GUISetState(@SW_SHOW,$g_hForm)


$hGUI2 = GUICreate("Ignore me", 300, 300,30,30)
GUICtrlCreateLabel('IGNORE ME...', 10, 10, 280, 20)
GUISetState(@SW_SHOW, $hGUI2)

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

Func _SubclassProc($hWnd, $iMsg, $wParam, $lParam, $iID, $pData)
    Return _WinAPI_DefSubclassProc($hWnd, $iMsg, $wParam, $lParam)
EndFunc   ;==>_SubclassProc

Func OnAutoItExit()
    _WinAPI_RemoveWindowSubclass(GUICtrlGetHandle($hInput), $g_pDll, 1000)
    _WinAPI_RemoveWindowSubclass(GUICtrlGetHandle($hInput2), $g_pDll, 1001)
    DllCallbackFree($g_hDll)
EndFunc   ;==>OnAutoItExit

Func WM_ACTIVATE($hWnd, $Msg, $wParam, $lParam)
  ; The two controls that are subclassed should not have focus when
  ; $g_hForm is deactivated. Set focus to $idLabel (or a hidden label).
  If $hWnd = $g_hForm And Not $wParam Then ControlFocus( $g_hForm, "", $idLabel )
EndFunc

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...