KaFu Posted November 4, 2022 Share Posted November 4, 2022 (edited) Hiho Forum, I found older postings where controlclick on hidden GUIs worked, now it does not seem to work anymore, a bug? Local $hGUI = GUICreate("Example") Local $c_Button = GUICtrlCreateButton("Test", 10, 10, 100) ; GUISetState(@SW_SHOW, $hGUI) ControlClick($hGUI, "", $c_Button) While 1 Switch GUIGetMsg() Case $c_Button MsgBox(0, "", "Click") Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd Edit: the same with onevent mode #include <GUIConstantsEx.au3> Opt("GUIOnEventMode", 1) Local $hGUI = GUICreate("Example") Local $c_Button = GUICtrlCreateButton("Test", 10, 10, 100) GUICtrlSetOnEvent(-1, "ButtonPressed") ; GUISetState(@SW_SHOW, $hGUI) ControlClick($hGUI, "", $c_Button) Sleep(1000) Func ButtonPressed() MsgBox(0, "", "Click") EndFunc Edited November 4, 2022 by KaFu OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
pixelsearch Posted November 4, 2022 Share Posted November 4, 2022 (edited) Hi KaFu Just tested your code on 2 older AutoIt releases (oldest one being v3.2.10.0 dated 2007) with same result as yours (controlclick on hidden GUI didn't work) What seems to work is adding a couple of lines, then ControlClick will be done while the GUI is hidden : Local $hGUI = GUICreate("Example") Local $c_Button = GUICtrlCreateButton("Test", 10, 10, 100) GUISetState(@SW_SHOW, $hGUI) ; or @SW_SHOWNA @SW_SHOWNOACTIVATE WinSetState($hGUI, '', @SW_HIDE) ; not GUISetState(@SW_HIDE, $hGUI) ControlFocus($hGUI, "", $c_Button) ControlClick($hGUI, "", $c_Button) While 1 Switch GUIGetMsg() Case $c_Button MsgBox(0, "Button", "Click") ExitLoop Case -3 ; $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd Same with OnEvent mode : Opt("GUIOnEventMode", 1) Local $hGUI = GUICreate("Example") Local $c_Button = GUICtrlCreateButton("Test", 10, 10, 100) GUICtrlSetOnEvent(-1, "ButtonPressed") GUISetState(@SW_SHOW, $hGUI) ; or @SW_SHOWNA @SW_SHOWNOACTIVATE WinSetState($hGUI, '', @SW_HIDE) ; not GUISetState(@SW_HIDE, $hGUI) ControlFocus($hGUI, "", $c_Button) ControlClick($hGUI, "", $c_Button) Sleep(1000) Func ButtonPressed() MsgBox(0, "Button", "Click") EndFunc Edited November 4, 2022 by pixelsearch replaced _WinAPI_SetFocus() with ControlFocus() Link to comment Share on other sites More sharing options...
KaFu Posted November 4, 2022 Author Share Posted November 4, 2022 I guess the default WNDPROC is only hooked once @SW_SHOW is called. Might be a good feature to hook this with GUISetState(@SW_HIDE, $hGUI) too? OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
pixelsearch Posted November 4, 2022 Share Posted November 4, 2022 Overlord, where are you ? argumentum 1 Link to comment Share on other sites More sharing options...
argumentum Posted November 4, 2022 Share Posted November 4, 2022 5 hours ago, KaFu said: default WNDPROC is only hooked once @SW_SHOW is called ...well, if WinSetState is called ( with @SW_HIDE ). As far as I remembered the call was always needed. But my mileage memory may vary Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting. Link to comment Share on other sites More sharing options...
pixelsearch Posted November 4, 2022 Share Posted November 4, 2022 Just modified the 2 scripts above. No need of _WinAPI_SetFocus() when ControlFocus() does the job. Then no need of #include <WinAPISysWin.au3> or an eventual $h_Button . Shorter code, same result. Link to comment Share on other sites More sharing options...
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