fett8802 Posted November 1, 2011 Share Posted November 1, 2011 (edited) Hello All, My problem is that I'm 'closing' a program to the tray instead of closing it outright. Many programs do this to save the room on the taskbar but keep the service running. It's a TCP monitoring program. Minimizing still minimizes to the taskbar. The actual program contains a significant amount of proprietary information, so I wrote a short replication script. This script operates very similarly to the program I've written and duplicates the problems. When you first run the script, observe that you can click the "On" and "Off" buttons which activate/deactivates the opposing button. Now, minimize the program and restore it. Verify that you can still operate the buttons properly. Now, click the 'X-Out' button to close the program to the tray. You can now restore the program either by right clicking and selecting restore, or by double clicking. Observe that, after restoral, the buttons can no longer be clicked correctly but that all other functions (minimizing, tray menu) work correctly. Let me know if you have any suggestions! Thanks! - Fett Note: After further testing, it seems like the program no longer recognizes the OnEvent for the buttons. expandcollapse popup#include <ButtonConstants.au3> #include <Constants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Opt("GUIOnEventMode", 1) Opt("TrayOnEventMode", 1) ;Set the AutoIt Mode to On Event Opt("TrayAutoPause",0) ;Turns off the auto pause when the tray icon is clicked Opt("TrayMenuMode",9) ;Remove the default exit, script paused controls from the tray menu Global $sToggle = 0, $bToggle = 0, $mToggle = 0 $gMain = GUICreate("", 122, 42, 192, 124) GUISetOnEvent($GUI_EVENT_CLOSE, "gClose") $Button1 = GUICtrlCreateButton("ON", 8, 8, 49, 25, $WS_GROUP) GUICtrlSetOnEvent(-1, "ButtonClick") $Button2 = GUICtrlCreateButton("OFF", 64, 8, 49, 25, $WS_GROUP) GUICtrlSetOnEvent(-1, "ButtonClick") GUICtrlSetState(-1, $GUI_DISABLE) $gTrayMenuRestore = TrayCreateItem("Restore", -1) ;Create a Tray Item option for restoring the GUI TrayItemSetOnEvent($gTrayMenuRestore, "tClick") ;Set the OnEvent for the above control $gTrayMenuLine = TrayCreateItem("", -1) ;Create a Tray Item option for restoring the GUI $gTrayMenuExit = TrayCreateItem("Exit", -1) ;Create a Tray Item option for restoring the GUI TrayItemSetOnEvent($gTrayMenuExit, "tClick") ;Set the OnEvent for the above control TraySetOnEvent($TRAY_EVENT_PRIMARYDOUBLE,"tClick") ;Set the OnEvent for when the user double clicks the tray TraySetClick(16) ;Set it so that only releasing the secondary mouse button will display the tray menu GUISetState(@SW_SHOW) While 1 If $bToggle = 0 And $mToggle = 0 Then GUICtrlSetState($Button2, $GUI_DISABLE) GUICtrlSetState($Button1, $GUI_ENABLE) $mToggle = 1 EndIf If $bToggle = 1 And $mToggle = 1 Then GUICtrlSetState($Button2, $GUI_ENABLE) GUICtrlSetState($Button1, $GUI_DISABLE) $mToggle = 0 EndIf Sleep(10) WEnd Func ButtonClick() If @GUI_CtrlId = $Button1 And $bToggle = 0 Then $bToggle = 1 If @GUI_CtrlId = $Button2 And $bToggle = 1 Then $bToggle = 0 EndFunc Func Form1Close() Exit EndFunc Func gClose() Switch @GUI_WINHANDLE ;Begin a switch conditional based on which GUI called the function Case $gMain ;If the Main GUI called the function, then GUISetState(@SW_HIDE, $gMain) ;Hide the Main GUI Return ;Return from the function EndSwitch ;End the switch conditional Exit EndFunc ;==>gClose Func tClick() If @TRAY_ID = $gTrayMenuExit Then Exit WinSetState($gMain,"",@SW_SHOW) ;Restore the main GUI window EndFunc Edited November 1, 2011 by fett8802 [sub]My UDF[/sub][sub] - Basics and Time extensions. Great for those new at AutoIt, also contains some powerful time extensions for pros.[/sub][sub]ScrabbleIt[/sub][sub] - Scrabble done in pure AutoIt. (In Progress)[/sub][sub]Nerd Party Extreme | My Portfolio | [email="fett8802@gmail.com"]Contact Me[/email][/sub] Link to comment Share on other sites More sharing options...
kaotkbliss Posted November 1, 2011 Share Posted November 1, 2011 (edited) by adding AutoItSetOption("trayicondebug", 1) I found that your example is getting stuck on line 38 (the Sleep in your while 1 loop.) since the only 2 things it's checking are $bToggle = 0 And $mToggle = 0 or $bToggle = 1 And $mToggle = 1 my conclusion is that the flags are not set to either of those conditions (one of the flags is a 1 and the other is a 0) *edit* After adding a Gui to update and show the current toggle values of $bToggle and $mToggle, that is exaclt the problem They are never both 0 or both 1, hence when you restore it gets stuck in the while loop waiting for a condition that will never happen Edited November 1, 2011 by kaotkbliss 010101000110100001101001011100110010000001101001011100110010000 001101101011110010010000001110011011010010110011100100001 My Android cat and mouse gamehttps://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek We're gonna need another Timmy! Link to comment Share on other sites More sharing options...
wraithdu Posted November 1, 2011 Share Posted November 1, 2011 Use GuiSetState(@SW_SHOW, $gMain) instead of WinSetState(). It affects internal GUI handling. I assume GuiSetState(@SW_HIDE) suspends AutoIt's internal GUI handling to save on resources. Link to comment Share on other sites More sharing options...
fett8802 Posted November 1, 2011 Author Share Posted November 1, 2011 Use GuiSetState(@SW_SHOW, $gMain) instead of WinSetState(). It affects internal GUI handling. I assume GuiSetState(@SW_HIDE) suspends AutoIt's internal GUI handling to save on resources. Thank you both very much for your timely responses. The above quote did the trick! - Fett [sub]My UDF[/sub][sub] - Basics and Time extensions. Great for those new at AutoIt, also contains some powerful time extensions for pros.[/sub][sub]ScrabbleIt[/sub][sub] - Scrabble done in pure AutoIt. (In Progress)[/sub][sub]Nerd Party Extreme | My Portfolio | [email="fett8802@gmail.com"]Contact Me[/email][/sub] Link to comment Share on other sites More sharing options...
kaotkbliss Posted November 1, 2011 Share Posted November 1, 2011 Use GuiSetState(@SW_SHOW, $gMain) instead of WinSetState(). It affects internal GUI handling. I assume GuiSetState(@SW_HIDE) suspends AutoIt's internal GUI handling to save on resources.Ahh, I didn't even catch thatNormally I try not to mix command types like that just out of consistancy so I didn't notice the Win/Gui change 010101000110100001101001011100110010000001101001011100110010000 001101101011110010010000001110011011010010110011100100001 My Android cat and mouse gamehttps://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek We're gonna need another Timmy! 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