Jump to content

ControlClick() fails for button in a Hidden GUI

Recommended Posts


I am attempting to use _Singleton() and a hidden AutoIt3 GUI so a message can be sent from a second instance of a script to the initial instance of a script. The GUI operates in event mode.

From within _Singleton(), ControlCommand($ScriptName, "", "[CLASS:ListBox; INSTANCE:1]", "AddString", $requestedState) adds a message to a ListBox in the GUI. This does not generate an event so I placed a button that can be clicked to generate an event.

ControlClick($ScriptName, "", "[CLASS:Button; TEXT:sendMsg; INSTANCE:1]")

The ControlClick() only works if the GUI is visible: GUISetState(@SW_SHOW) .

If the GUI is hidden, GUISetState(@SW_HIDE), ControlCommand() does add the message to the list but

ControlClick() does not fire an event for my ASendMSGButton1Click() function.

I added a WinActivate($ScriptName) prior to the ControlClick() but it still fails in hidden mode.

The event functions and GUI were initially generated with KODA.

Any ideas on how to generate any type of event for a hidden GUI?

Original _Singleton() with a message passing GUI idea:


Edited by CraigA

Share this post

Link to post
Share on other sites

I received an IM type reply to try this: Opt("WinDetectHiddenText", 1) but the problem remains.

Prior to my post above, I also tried a checkBox and using ControlEnable($ScriptName, "", "[CLASS:Button; INSTANCE:2]") to check or uncheck to generate an event but same results: no event fired if GUISetState(@SW_HIDE).

Does anyone know if ControlCommand($ScriptName, "", "[CLASS:ListBox; INSTANCE:1]", "AddString", $requestedState) might be generating an event that KODA did not include?

KODA did generate AmsgList1Click() but ControlClick($ScriptName, "", "[CLASS:ListBox; INSTANCE:1]")does not fire an event when the GUI is hidden.

Share this post

Link to post
Share on other sites

Perhaps a little code will inspire someone.

#Include <Constants.au3>
#include <IE.au3>
#include <SiteMinder.au3>
#include <GUIConstants.au3>
#Include <GuiListBox.au3>

#include <Misc.au3>   ; http://www.autoitscript.com/forum/index.php?showtopic=37289 Question 3.

#include <SiteMinderMonConsts.au3>
; Global Constant for SiteMinderMonitor.au3
; """""""""""""""
;   Desired Mode
;   $MONITORING - Constantly Monitoring
;   $DEAD - Exit this script.

;#NoTrayIcon   ; Turn OFF the tray icon.

Opt("GUIOnEventMode", 1)
;Opt("GUIEventOptions", 1)   ; Disable but still report minimize, restore, maximize, etc.
Opt("WinDetectHiddenText", 1)

Local $ScriptName = StringLeft(@ScriptName, StringLen(@ScriptName) - 4)
Local $AmsgForm1, $AmsgList1, $ASendMSGButton1
Local $requestedState
Local $oIE  ; The Internet Explorer Object.


Func Main()
    If $CmdLine[0] <> 0 Then
        ;Some command line args
        $requestedState = $CmdLine[1]
        $requestedState = $MONITORING
    If _Singleton("SiteMinderMonitor", 1) == 0 Then 
        ; Send a message to the initial running instance.
        ControlCommand($ScriptName, "", "[CLASS:ListBox;  INSTANCE:1]", "AddString", $requestedState)
        ControlClick($ScriptName, "", "[CLASS:Button; TEXT:sendMsg; INSTANCE:1]")

    ; Only the first running instance gets past this point.

    If $requestedState = $DEAD Then
        ; First launch was a request to die.

    Opt("WinWaitDelay", 100)
    Opt("WinTitleMatchMode", 4)

    ; Create an invisible GUI to receive messages from subsequent instances.
    #Region ### START Koda GUI section ### Form=
    $AmsgForm1 = GUICreate($ScriptName, 180, 194, 100, 115)
    GUISetOnEvent($GUI_EVENT_CLOSE, "AmsgForm1Close")
    GUISetOnEvent($GUI_EVENT_MINIMIZE, "AmsgForm1Minimize")
    GUISetOnEvent($GUI_EVENT_MAXIMIZE, "AmsgForm1Maximize")
    GUISetOnEvent($GUI_EVENT_RESTORE, "AmsgForm1Restore")
    $AmsgList1 = GUICtrlCreateList("", 8, 8, 89, 123, $WS_BORDER)   ; $WS_BORDER - Odd way of turning off default sort.
    GUICtrlSetOnEvent(-1, "AmsgList1Click")
    $ASendMSGButton1 = GUICtrlCreateButton("sendMsg", 16, 144, 75, 25, 0)
    GUICtrlSetOnEvent(-1, "ASendMSGButton1Click")
    #EndRegion ### END Koda GUI section ###

    Local $showItem = TrayCreateItem("ShowToggle")

    While 1   ; Loop Forever.
        WinWaitActive("[TITLE:LOGIN - V; CLASS:IEFrame]", "")
        ; Attach to the first existing instance of Internet Explorer where 
        ; the search string sub-string matches based on the selected mode.
        $oIE = _IEAttach("LOGIN - Verizon")
        ; There was a "Login" form, so login but don't Exit if Login Fails.
        SiteMinderLogin ($oIE, False)
EndFunc ; <===<< Main()

Func ASendMSGButton1Click()
    MsgBox(0, "SiteMinderMonitor", "Send MSG Button Clicked")
    ;Check for a new entry in the listbox
    If _GUICtrlListBox_GetCount($AmsgList1) > 0 Then
        $requestedState = _GUICtrlListBox_GetText($AmsgList1, 0)
        ;Remove the processed entry
        _GUICtrlListBox_DeleteString($AmsgList1, 0)
        Switch $requestedState
            Case $MONITORING
                ; do nothing. Should aready be monitoring otherwise it is Dead.
            Case $DEAD
            Case Else
                ; Write to error Log on Server
                MsgBox(0, "SiteMinderMonitor Error:", "Unknown Msg: " & $requestedState)
            $ret = _GUICtrlListDeleteItem($AmsgList1, 0)
            If ($ret == $LB_ERR) Then
            MsgBox(16, "Error", "Unknown error from _GUICtrlListDeleteItem")
        ; Write to error Log on Server.
        MsgBox(0, "SiteMinderMonitor Error:", "No message found in list.")
EndFunc   ;==>ASendMSGButton1Click

Func AmsgForm1Close()
EndFunc   ;==>AmsgForm1Close

Func AmsgForm1Maximize()
    MsgBox(0, "SiteMinderMonitor", "Max GUI")
EndFunc   ;==>AmsgForm1Maximize

Func AmsgForm1Minimize()
    MsgBox(0, "SiteMinderMonitor", "Minimize GUI")
EndFunc   ;==>AmsgForm1Minimize

Func AmsgForm1Restore()
    MsgBox(0, "SiteMinderMonitor", "Restore GUI")
EndFunc   ;==>AmsgForm1Restore

Func AmsgList1Click()
    MsgBox(0, "SiteMinderMonitor", "MSG List Item Clicked")
EndFunc   ;==>AmsgList1Click

Func ACheckbox1Click()
    MsgBox(0, "SiteMinderMonitor", "Checkbox Clicked")

; Toggle visibility of Message GUI.
Func _toggleShow()
    If IsVisible($AmsgForm1) Then
        MsgBox(0,"","got to _toggleShow. Should be hidden now.")
        MsgBox(0,"","got to _toggleShow. Should be visible now.")

Func IsVisible($handle)
  If BitAnd( WinGetState($handle), 2 ) Then 
    Return 1
    Return 0

Once SiteMinderMonitor is launched, you can toggle the visibility of its message GUI from its tray icon.

Another script should be able to ShellExecute("SiteMinderMonitor.exe", 1) to kill SiteMinderMonitor whether or not its GUI is visible but it only kills when it is visible.

ControlClick($ScriptName, "", "[CLASS:Button; TEXT:sendMsg; INSTANCE:1]") fails when not visible.

Last Friday I upgraded AutoIt3 to and today, upgraded SciTE to 1.74 but the bug remains.

Edited by CraigA

Share this post

Link to post
Share on other sites

I realize that this is an extremely old thread but maybe someone will find this from searching.

Anyways I found a sort-of workaround to this problem which is to create the GUI like this

GUICreate('', 0, 0, -100, -100, -1, $WS_EX_TOOLWINDOW)

This creates a GUI that is not actually hidden but appears offscreen and does not appear in the taskbar or alt-tab list and also does not take focus when it appears, so effectively it is hidden but the events still fire.

Share this post

Link to post
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