ISI360 Posted February 3, 2019 Posted February 3, 2019 (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. expandcollapse popup#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 February 3, 2019 by ISI360
Nine Posted February 3, 2019 Posted February 3, 2019 Like its name says it is subclassing windows, not fields. I do not understand what is you want to achieve with subclassing fields, tho...But in any case, I can reproduce the behavior too. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
Danp2 Posted February 3, 2019 Posted February 3, 2019 1 hour ago, Nine said: Like its name says it is subclassing windows, not fields. Seems that you fail to understand that controls on a window are actually windows themselves. Latest Webdriver UDF Release Webdriver Wiki FAQs
LarsJ Posted February 3, 2019 Posted February 3, 2019 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: expandcollapse popup#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 Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions
ISI360 Posted February 3, 2019 Author Posted February 3, 2019 Thank you LarsJ! Your workaround works and eliminates this strange error.
Nine Posted February 3, 2019 Posted February 3, 2019 7 hours ago, Danp2 said: Seems that you fail to understand that controls on a window are actually windows themselves. Thank you so much for reminding me. You are such a great MVP. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now