Jump to content

Controlclick on hidden GUI not working


KaFu
 Share

Recommended Posts

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 by KaFu
Link to comment
Share on other sites

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 by pixelsearch
replaced _WinAPI_SetFocus() with ControlFocus()
Link to comment
Share on other sites

Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

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