Sign in to follow this  
Followers 0
SlowCoder74

ControlClick not working?

7 posts in this topic

My test code:

#NoTrayIcon
Opt("TrayMenuMode", 1+2) ;remove 'script paused' and 'exit' from tray menu

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 312, 222, 494, 647)
$btnPause = GUICtrlCreateButton("Pause", 24, 16, 57, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

$TrayPause = TrayCreateItem("Pause")
$TrayClose = TrayCreateItem("Close")
TraySetState()


local $bPaused = False

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $btnPause
            $bPaused = Not $bPaused
            if $bPaused = True Then
                GUICtrlSetData($btnPause,"Resume")
                Else
                GUICtrlSetData($btnPause,"Pause")
            EndIf
    EndSwitch

    ;GET TRAY MESSAGES
    $TrayMsg = TrayGetMsg()
    Switch $TrayMsg
        Case $TrayClose
            Exit
        Case $TrayPause
            ControlClick($Form1,"",$btnPause)
    EndSwitch
WEnd

When I click the Pause from the system tray menu, it does not toggle the pause button on the form.  I'm unable to determine why.

In one of the apps I'm developing, it will work the first time, but only once.  I can click the button itself and it toggles as expected.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

If the script pauses, how do you expect the script to continue to update the text :)

You would almost need two scripts, one that 'pauses' the second, and the originator than updates some gui.

Oops, just noticed what you were doing...checking on that.

Edited by jdelaney

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

heh ... yeah, it's just dummy data.  Not actually pausing anything.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

I was thinking at first you were using the standard tray icons...here's a workaround:

#NoTrayIcon
Opt("TrayMenuMode", 1+2) ;remove 'script paused' and 'exit' from tray menu

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 312, 222, 494, 647)
$btnPause = GUICtrlCreateButton("Pause", 24, 16, 57, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

$TrayPause = TrayCreateItem("Pause")
$TrayClose = TrayCreateItem("Close")
TraySetState()

Global $bPaused = False

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $btnPause
            ChangeText()
    EndSwitch

    ;GET TRAY MESSAGES
    $TrayMsg = TrayGetMsg()
    Switch $TrayMsg
        Case $TrayClose
            Exit
        Case $TrayPause
            ChangeText()
    EndSwitch
WEnd

Func ChangeText()
    if Not $bPaused Then
        $bPaused = True
        GUICtrlSetData($btnPause,"Resume")
    Else
        $bPaused = False
        GUICtrlSetData($btnPause,"Pause")
    EndIf
EndFunc

or

Func ChangeText()
    $bPaused = Not $bPaused
    if $bPaused Then
        GUICtrlSetData($btnPause,"Resume")
    Else
        GUICtrlSetData($btnPause,"Pause")
    EndIf
EndFunc
Edited by jdelaney

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

I'd thought of creating a separate function like what you've proposed.  But I would like to know why it isn't working in the first place. :

Share this post


Link to post
Share on other sites

Here, did some focusing/activating to make yours work:

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $btnPause
            $bPaused = Not $bPaused
            if $bPaused Then
                GUICtrlSetData($btnPause,"Resume")
                Else
                GUICtrlSetData($btnPause,"Pause")
            EndIf
            MsgBox(1,1,$bPaused)
    EndSwitch

    ;GET TRAY MESSAGES
    $TrayMsg = TrayGetMsg()
    Switch $TrayMsg
        Case $TrayClose
            Exit
        Case $TrayPause
            WinActivate($Form1)
            ControlFocus($Form1,"",$btnPause)
            ControlClick($Form1,"",$btnPause)
    EndSwitch
WEnd

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

Ah, not sure what I hadn't thought of that!  I just used the ControlFocus() and that allowed it to work.

You get a cookie! :thumbsup:

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
Sign in to follow this  
Followers 0