SAG Posted December 21, 2006 Posted December 21, 2006 I have a GUI which I am trying to minimize to the system tray. At the same time I am using the _Singleton function to allow only a single instance. I cannot get this to work completely - the second instance restores the original instance and makes it active but none of the AutoIt controls work (the Windows Minimize and Exit controls work) until the application icon in the tray is clicked. I can demonstrate the same behavior in these code examples below. Compile both. Run the first. See that the Button works and the GUI exits. Run it again and minimize it - it minimizes to the system tray as expected. Now run the second script (with the first still minimized). The second script activates the first window and exits but now the Button doesn't work. Click the tray icon for the first application and the button now works. (If the first script is not minimized and the second is used to make the first active, the Button continues to work.) The second script indicates that the Window state is 15 - exists, visible, enabled, and active. So why doesn't the Button work? What am I missing? How do I make this work? TIA GUI with a button (from ChrisL code) expandcollapse popup#include <GuiConstants.au3> #include <Constants.au3> Opt("TrayOnEventMode",1) Opt("TrayMenuMode",1) Opt("TrayIconHide", 0) TraySetOnEvent($TRAY_EVENT_PRIMARYUP,"SpecialEvent") TraySetState() GuiCreate("MyGUI", 392, 316,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS)) $exitButton = GUICtrlCreateButton("Exit", 20, 100, 40, 30) GuiSetState() While 1 $msg = GuiGetMsg() Switch $msg Case $GUI_EVENT_MINIMIZE GuiSetState(@SW_HIDE) Opt("TrayIconHide", 0) Case $GUI_EVENT_CLOSE , $exitButton ExitLoop Case Else ;;; EndSwitch WEnd Func SpecialEvent() GuiSetState(@SW_Show) Opt("TrayIconHide", 1) EndFunc Code to activate minimized first script if WinSetState("MyGUI", "", @SW_RESTORE) = 0 Then MsgBox(0, "WinSetState", "The MyGUI window is not found.") if WinActivate("MyGUI") = 0 Then MsgBox(0, "WinActivate", "The MyGUI window is not found.") if WinWaitActive("MyGUI") = 0 Then MsgBox(0, "WinWaitActivate", "The MyGUI window is not found.") $winState = WinGetState("MyGUI") MsgBox(0, "Window State", $winState)
GEOSoft Posted December 22, 2006 Posted December 22, 2006 I have a GUI which I am trying to minimize to the system tray. At the same time I am using the _Singleton function to allow only a single instance. I cannot get this to work completely - the second instance restores the original instance and makes it active but none of the AutoIt controls work (the Windows Minimize and Exit controls work) until the application icon in the tray is clicked. I can demonstrate the same behavior in these code examples below. Compile both. Run the first. See that the Button works and the GUI exits. Run it again and minimize it - it minimizes to the system tray as expected. Now run the second script (with the first still minimized). The second script activates the first window and exits but now the Button doesn't work. Click the tray icon for the first application and the button now works. (If the first script is not minimized and the second is used to make the first active, the Button continues to work.) The second script indicates that the Window state is 15 - exists, visible, enabled, and active. So why doesn't the Button work? What am I missing? How do I make this work? TIA GUI with a button (from ChrisL code) #include <GuiConstants.au3> #include <Constants.au3> Opt("TrayOnEventMode",1) Opt("TrayMenuMode",1) Opt("TrayIconHide", 0) TraySetOnEvent($TRAY_EVENT_PRIMARYUP,"SpecialEvent") TraySetState() GuiCreate("MyGUI", 392, 316,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS)) $exitButton = GUICtrlCreateButton("Exit", 20, 100, 40, 30) GuiSetState() While 1 $msg = GuiGetMsg() Switch $msg Case $GUI_EVENT_MINIMIZE GuiSetState(@SW_HIDE) Opt("TrayIconHide", 0) Case $GUI_EVENT_CLOSE , $exitButton ExitLoop Case Else ;;; EndSwitch WEnd Func SpecialEvent() GuiSetState(@SW_Show) Opt("TrayIconHide", 1) EndFunc Code to activate minimized first script if WinSetState("MyGUI", "", @SW_RESTORE) = 0 Then MsgBox(0, "WinSetState", "The MyGUI window is not found.") if WinActivate("MyGUI") = 0 Then MsgBox(0, "WinActivate", "The MyGUI window is not found.") if WinWaitActive("MyGUI") = 0 Then MsgBox(0, "WinWaitActivate", "The MyGUI window is not found.") $winState = WinGetState("MyGUI") MsgBox(0, "Window State", $winState)Are you calling the estore function from the singleton? If not give that a try Personall I just pop up a MsgBox saying that the window is allready active and please click the tray icon to restore it. Then Exit BTW I seldom need Singleton Instead I use $Ttl = "MyGui" If WinExixts($Ttl Then <Insert msgbox her> Exit EndIf George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!"
SAG Posted December 29, 2006 Author Posted December 29, 2006 Are you calling the estore function from the singleton? If not give that a try Personall I just pop up a MsgBox saying that the window is allready active and please click the tray icon to restore it. Then Exit BTW I seldom need Singleton Instead I use $Ttl = "MyGui" If WinExixts($Ttl Then <Insert msgbox her> Exit EndIf Thank you for your reply, GEOSoft. For sure your method would work in place of _Singleton. For the most part, this is an exercise in learning so I am still interested in why what I am trying does not work. I don't think it matters whether I use the _Singleton function or your solution; either would work the same way in my example. Why when the GUI is restored don't the controls work unless I first click on the tray icon? The code I listed that activates the window indicates the window is enabled, active, etc. Thank you for your thoughts.
SAG Posted January 10, 2007 Author Posted January 10, 2007 Let me take another swing at this. :"> As I mentioned, this is mostly an educational exercise and I'm stuck on this one. I'd like to minimize the application to the task tray. If the user tries to launch the application a second time, it should open the original application from the task tray. What I have works except that when the application opens from the task tray, the GUI components are not active. They are not active until the application in the task tray is clicked. The examples I posted previously demonstrate this behavior. The windows state indicate all is well - to me anyway. Can anyone offer any ideas? Thank you for your help.
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