SlowCoder74 Posted February 5, 2014 Share Posted February 5, 2014 My test code: expandcollapse popup#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 More sharing options...
jdelaney Posted February 5, 2014 Share Posted February 5, 2014 (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 February 5, 2014 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 More sharing options...
SlowCoder74 Posted February 5, 2014 Author Share Posted February 5, 2014 heh ... yeah, it's just dummy data. Not actually pausing anything. Link to comment Share on other sites More sharing options...
jdelaney Posted February 5, 2014 Share Posted February 5, 2014 (edited) I was thinking at first you were using the standard tray icons...here's a workaround: expandcollapse popup#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 February 5, 2014 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 More sharing options...
SlowCoder74 Posted February 5, 2014 Author Share Posted February 5, 2014 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. Link to comment Share on other sites More sharing options...
Solution jdelaney Posted February 5, 2014 Solution Share Posted February 5, 2014 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 More sharing options...
SlowCoder74 Posted February 5, 2014 Author Share Posted February 5, 2014 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! 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