steveR Posted March 15, 2005 Share Posted March 15, 2005 I have this sample code which toggles the gui to the tray. How can I have it minimize to the tray when the gui loses focus (e.g., switching to another program, or clicking off the gui)? I've tried several commands, but I keep getting conflicts. #include <guiconstants.au3> #include <constants.au3> ; Opt ("TrayAutoPause", 0) Opt ("TrayMenuMode", 1) ; $SHOW = 1 $HIDE = 0 $appState = $SHOW ; $guiQuestion = GUICreate( "Question", 200, 200) GUISetState() ; ; Do $guiMsg = GUIGetMsg() $trayMsg = TrayGetMsg() ; Select case $trayMsg = $TRAY_EVENT_PRIMARYDOWN Or $trayMsg = $TRAY_EVENT_PRIMARYDOUBLE _ToggleAppState() EndSelect ; until $guiMsg = $GUI_EVENT_CLOSE ; ; Func _ToggleAppState() if $appState = $HIDE then $appState = $SHOW GUISetState(@SW_SHOW, $guiQuestion) Return EndIf $appState = $HIDE GUISetState(@SW_HIDE, $guiQuestion) EndFunc AutoIt3 online docs Use it... Know it... Live it...MSDN libraryglobal Help and SupportWindows: Just another pane in the glass. Link to comment Share on other sites More sharing options...
SlimShady Posted March 15, 2005 Share Posted March 15, 2005 If NOT WinActive($guiQuestion) Then;Do whatever you want Link to comment Share on other sites More sharing options...
zcoacoaz Posted March 15, 2005 Share Posted March 15, 2005 you might want to set a variable and if it is already minimized it doesn't do it again. [font="Times"] If anyone remembers me, I am back. Maybe to stay, maybe not.----------------------------------------------------------------------------------------------------------[/font][font="Times"]Things I am proud of: Pong! in AutoIt | SearchbarMy website: F.R.I.E.S.A little website that is trying to get started: http://thepiratelounge.net/ (not mine)[/font][font="Times"] ----------------------------------------------------------------------------------------------------------[/font][font="Arial"]The newbies need to stop stealing avatars!!! It is confusing!![/font] Link to comment Share on other sites More sharing options...
steveR Posted March 15, 2005 Author Share Posted March 15, 2005 (edited) Ok, this is where i have the problem. It now goes to the tray if the gui loses focus, and it will activate if I click the tray. But when I try to minimize by clicking the tray, it seems to fire twice. Once to minimize it, then once to bring it back up. In summary, I want to be able to minimize and raise it with the tray icon, or minimize box. Also I want it to minimize when the gui loses focus. expandcollapse popup#include <guiconstants.au3> #include <constants.au3> ; Opt ("TrayAutoPause", 0) Opt ("TrayMenuMode", 1) ; $YES = 1 $NO = 0 $focused = $YES $SHOW = 1 $HIDE = 0 $appState = $SHOW ; $guiQuestion = GUICreate( "Question", 200, 200) GUISetState() ; ; Do $guiMsg = GUIGetMsg() $trayMsg = TrayGetMsg() ; if Not WinActive("Question") Then if $focused = $YES Then $appState = $SHOW _ToggleAppState() EndIf EndIf ; Select GUISetState(@SW_HIDE, $guiQuestion) case $trayMsg = $TRAY_EVENT_PRIMARYDOWN Or $trayMsg = $TRAY_EVENT_PRIMARYDOUBLE _ToggleAppState() EndSelect ; until $guiMsg = $GUI_EVENT_CLOSE ; ; Func _ToggleAppState() if $appState = $HIDE then $appState = $SHOW $focused = $YES GUISetState(@SW_SHOW, $guiQuestion) Return EndIf $appState = $HIDE $focused = $NO GUISetState(@SW_HIDE, $guiQuestion) EndFunc ; ; Edited March 15, 2005 by steveR AutoIt3 online docs Use it... Know it... Live it...MSDN libraryglobal Help and SupportWindows: Just another pane in the glass. Link to comment Share on other sites More sharing options...
steveR Posted March 15, 2005 Author Share Posted March 15, 2005 I still havent't been able to figure this out AutoIt3 online docs Use it... Know it... Live it...MSDN libraryglobal Help and SupportWindows: Just another pane in the glass. Link to comment Share on other sites More sharing options...
Holger Posted March 15, 2005 Share Posted March 15, 2005 (edited) A little bit shorted:expandcollapse popup#include <guiconstants.au3> #include <constants.au3> ; Opt ("TrayAutoPause", 0) Opt ("TrayMenuMode", 1) ; ; $guiQuestion = GUICreate( "Question", 200, 200) GUISetState() $appState = @SW_SHOW ; ; Do $guiMsg = GUIGetMsg() $trayMsg = TrayGetMsg() if Not WinActive("Question") And $appState = @SW_SHOW Then _ToggleAppState() EndIf Select case $trayMsg = $TRAY_EVENT_PRIMARYDOWN _ToggleAppState() EndSelect ; until $guiMsg = $GUI_EVENT_CLOSE ; ; Func _ToggleAppState() if $appState = @SW_HIDE then $appState = @SW_SHOW GUISetState(@SW_SHOW, $guiQuestion) Else $appState = @SW_HIDE GUISetState(@SW_HIDE, $guiQuestion) EndIf EndFunc ; ;Regards HolgerEdit Did forget something, the behaviour was normal cause:- when you click on the tray icon then the window loses the focus automatically -> and so it will be hidden- but then there is still a click message in the queue which then toggles automatically the window state to show itSo the script is not fully working... Edited March 15, 2005 by Holger Old project:GUI/Tray menu with icons and colors Other old stuff:IconFileScanner, TriState/ThreeState GUI TreeView, GUI ContextMenu created out of a TreeView Link to comment Share on other sites More sharing options...
steveR Posted March 15, 2005 Author Share Posted March 15, 2005 Thanks for the effort Holger, but i still have the problem of it firing twice. Here i added traytips and sleep() to help see it better expandcollapse popup#include <guiconstants.au3> #include <constants.au3> ; Opt ("TrayAutoPause", 0) Opt ("TrayMenuMode", 1) #include <guiconstants.au3> #include <constants.au3> ; Opt ("TrayAutoPause", 0) Opt ("TrayMenuMode", 1) ; $YES = 1 $NO = 0 $focused = $YES $SHOW = 1 $HIDE = 0 $appState = $SHOW ; $guiQuestion = GUICreate( "Question", 200, 200) GUISetState() ; ; Do $guiMsg = GUIGetMsg() $trayMsg = TrayGetMsg() ; if Not WinActive("Question") Then if $focused = $YES Then $appState = $SHOW _ToggleAppState() EndIf EndIf ; Select GUISetState(@SW_HIDE, $guiQuestion) case $trayMsg = $TRAY_EVENT_PRIMARYDOWN Or $trayMsg = $TRAY_EVENT_PRIMARYDOUBLE _ToggleAppState() EndSelect ; until $guiMsg = $GUI_EVENT_CLOSE ; ; Func _ToggleAppState() if $appState = $HIDE then traytip("showing"," ", 1) sleep(1000) $appState = $SHOW $focused = $YES GUISetState(@SW_SHOW, $guiQuestion) Return EndIf traytip("hiding"," ", 1) sleep(1000) $appState = $HIDE $focused = $NO GUISetState(@SW_HIDE, $guiQuestion) EndFunc ; ; AutoIt3 online docs Use it... Know it... Live it...MSDN libraryglobal Help and SupportWindows: Just another pane in the glass. Link to comment Share on other sites More sharing options...
Holger Posted March 15, 2005 Share Posted March 15, 2005 Try this: expandcollapse popup; #include <guiconstants.au3> #include <constants.au3> ; Opt ("TrayAutoPause", 0) Opt ("TrayMenuMode", 1) ; $guiQuestion = GUICreate( "Question", 200, 200) GUISetState() $appState = @SW_SHOW $clicked = 0 ; ; Do $guiMsg = GUIGetMsg() $trayMsg = TrayGetMsg() If $appstate = @SW_SHOW And Not WinActive("Question") Then _ToggleAppState() $clicked = 1 EndIf Select Case $trayMsg = $TRAY_EVENT_PRIMARYDOWN Or $trayMsg = $TRAY_EVENT_PRIMARYDOUBLE If $clicked = 0 Then _ToggleAppState() $clicked = 1 Else $clicked = 0 EndIf EndSelect ; until $guiMsg = $GUI_EVENT_CLOSE ; ; Func _ToggleAppState() If $appState = @SW_HIDE then TrayTip("showing"," ", 1) GUISetState(@SW_SHOW, $guiQuestion) $appState = @SW_SHOW Else TrayTip("hiding"," ", 1) GUISetState(@SW_HIDE, $guiQuestion) $appState = @SW_HIDE EndIf EndFunc ; ; Regards Holger Old project:GUI/Tray menu with icons and colors Other old stuff:IconFileScanner, TriState/ThreeState GUI TreeView, GUI ContextMenu created out of a TreeView Link to comment Share on other sites More sharing options...
Toppy Posted April 13, 2005 Share Posted April 13, 2005 Where do you guys get this from ?Only things I get when running is ERROR: Unknown function name: TrayGetMsg() Link to comment Share on other sites More sharing options...
steveR Posted April 13, 2005 Author Share Posted April 13, 2005 Tray functions are not in the stable release version yet. They are in the beta. AutoIt3 online docs Use it... Know it... Live it...MSDN libraryglobal Help and SupportWindows: Just another pane in the glass. Link to comment Share on other sites More sharing options...
Toppy Posted April 13, 2005 Share Posted April 13, 2005 ah OK, thanks :"> Link to comment Share on other sites More sharing options...
TuMbLeWeEd Posted April 17, 2005 Share Posted April 17, 2005 (edited) Made it a lot simpler (it works on my pc) expandcollapse popup; #include <guiconstants.au3> #include <constants.au3> ; Opt ("TrayAutoPause", 0) Opt ("TrayMenuMode", 1) ; $guiQuestion = GUICreate( "Question", 200, 200) GUISetState() $appState = @SW_SHOW $clicked = 0 TraySetClick(16) ; ; Do $guiMsg = GUIGetMsg() $trayMsg = TrayGetMsg() if Not WinActive("Question") and $clicked = 1 Then ;sleep(1000);waits a second before setting to tray GUISetState(@SW_HIDE, $guiQuestion) $clicked = 0 EndIf Select Case $trayMsg = $TRAY_EVENT_PRIMARYDOWN or $trayMsg = $TRAY_EVENT_PRIMARYDOUBLE If $clicked = 0 Then sleep(100) GUISetState(@SW_SHOW, $guiQuestion) $clicked = 1 Else GUISetState(@SW_HIDE, $guiQuestion) $clicked = 0 EndIf Case $guiMsg = $GUI_EVENT_MINIMIZE GUISetState(@SW_HIDE, $guiQuestion) $clicked = 0 EndSelect ; until $guiMsg = $GUI_EVENT_CLOSE EDIT: and its stil not minimizing on tray click, damn (then i have got the same prob in my app's) Edited April 17, 2005 by TuMbLeWeEd My AutoIt stuffChatBichProjectSelectorWindow control grabberUsefull LinksPort forwarding with routers Link to comment Share on other sites More sharing options...
SlimShady Posted April 17, 2005 Share Posted April 17, 2005 This one is working better. #include <guiconstants.au3> #include <constants.au3> ; Opt ("TrayAutoPause", 0) Opt ("TrayMenuMode", 1) ; $guiQuestion = GUICreate( "Question", 200, 200) GUISetState() $hidden = 0 TraySetClick(16) ; ; Do $guiMsg = GUIGetMsg() $trayMsg = TrayGetMsg() Select Case $trayMsg = $TRAY_EVENT_PRIMARYDOWN If $hidden Then sleep(100) GUISetState(@SW_SHOW, $guiQuestion) Else GUISetState(@SW_HIDE, $guiQuestion) EndIf $hidden = NOT $hidden Case $guiMsg = $GUI_EVENT_MINIMIZE GUISetState(@SW_HIDE, $guiQuestion) $hidden = 1 EndSelect ; until $guiMsg = $GUI_EVENT_CLOSE Link to comment Share on other sites More sharing options...
TuMbLeWeEd Posted April 17, 2005 Share Posted April 17, 2005 (edited) You forgot his primary intension, he want to minimize to the tray if the window loses the focusLookt at it for a few minits a realized that you should include the minimize to tray on focus los in the select case like this expandcollapse popup; #include <guiconstants.au3> #include <constants.au3> ; Opt ("TrayAutoPause", 0) Opt ("TrayMenuMode", 1) ; $guiQuestion = GUICreate( "Question", 200, 200) GUISetState() $clicked = 1;window is at state show at launch TraySetClick(16) ; ; Do $guiMsg = GUIGetMsg() $trayMsg = TrayGetMsg() Select Case Not WinActive("Question") and $clicked = 1 ConsoleWrite("Lost focus minimize" & @lf ) GUISetState(@SW_HIDE, $guiQuestion) $clicked = 0 Case $trayMsg = $TRAY_EVENT_PRIMARYDOUBLE;dont use single event (still gets confused then) ConsoleWrite("Tray clicked" & @lf ) If $clicked = 0 Then GUISetState(@SW_SHOW, $guiQuestion) $clicked = 1 ConsoleWrite("Show from tray" & @lf ) EndIf Case $guiMsg = $GUI_EVENT_MINIMIZE ConsoleWrite("Minimize in window" & @lf ) GUISetState(@SW_HIDE, $guiQuestion) $clicked = 0 EndSelect ; until $guiMsg = $GUI_EVENT_CLOSEIt is that simple, but it takes a while to figure out Edited April 17, 2005 by TuMbLeWeEd My AutoIt stuffChatBichProjectSelectorWindow control grabberUsefull LinksPort forwarding with routers 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