Jump to content

ControlClick not working?


Go to solution Solved by jdelaney,

Recommended Posts

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.

Link to comment
Share on other sites

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

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

  • Solution

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.
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...