ESPUser 0 Posted May 15, 2020 Share Posted May 15, 2020 Hello, I hope you can help me out on this: I tried to create a gui which also has a tray icon and which minimizes to tray, Everything works just fine when i start the gui with @SW_SHOW and then minimze it by clicking on the _ button of the GUI. But when i start it with @SW_MINIMIZED and then restore it from the tray, the GUI button does not work (the X Button still does work). What am i doing wrong here? Here is my minimal code to show the problem: #include <GUIConstants.au3> Opt("TrayMenuMode", 3) TraySetIcon("Shell32.dll", -87) TraySetClick(9) $RestoreTray = TrayCreateItem("Show") $ExitTray = TrayCreateItem("Close") $guiname = "MyGUI" $main_gui = GUICreate($guiname, 200, 200) $idclosewin = GUICtrlCreateButton("Close", 10, 10) ;GUISetState(@SW_MINIMIZE, $main_gui) GUISetState(@SW_SHOW, $main_gui) While 1 Switch GUIGetMsg() Case $GUI_EVENT_MINIMIZE $winstate = WinGetState($main_gui) If BitAND($winstate, 16) Or Not BitAND($winstate, 2) Then WinSetState($main_gui, "", @SW_HIDE) EndIf Case $GUI_EVENT_CLOSE, $idclosewin Exit EndSwitch Switch TrayGetMsg() Case $RestoreTray WinSetState($main_gui, "", @SW_RESTORE) Case $ExitTray Exit EndSwitch WEnd Link to post Share on other sites
Moderators Melba23 3,799 Posted May 15, 2020 Moderators Share Posted May 15, 2020 ESPUser, Your script works fine for me - the button exits the script every time. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to post Share on other sites
ESPUser 0 Posted May 15, 2020 Author Share Posted May 15, 2020 So if you uncomment GUISetState(@SW_MINIMIZE, $main_gui) and comment out GUISetState(@SW_SHOW, $main_gui) the script starts with only a tray icon and you can then restore the gui from the tray icon with the Show command and you can then exit the gui with the X and the Close button as well? When i do this, the GUI X works fine all the time, but the close button only works when i start the script with SW_SHOW Link to post Share on other sites
ESPUser 0 Posted May 15, 2020 Author Share Posted May 15, 2020 I added some Console output to research the problem: #include <GUIConstants.au3> Opt("TrayMenuMode", 3) TraySetIcon("Shell32.dll", -87) TraySetClick(9) $RestoreTray = TrayCreateItem("Show") $ExitTray = TrayCreateItem("Close") $guiname = "MyGUI" $main_gui = GUICreate($guiname, 200, 200) $idclosewin = GUICtrlCreateButton("Close", 10, 10) ConsoleWrite("$idclosewin: " & $idclosewin & @CRLF) GUISetState(@SW_MINIMIZE, $main_gui) ;GUISetState(@SW_SHOW, $main_gui) While 1 $msg = GUIGetMsg() If $msg <> 0 And $msg <> -11 Then ConsoleWrite("$msg: " & $msg & @CRLF) Switch $msg Case $GUI_EVENT_MINIMIZE $winstate = WinGetState($main_gui) If BitAND($winstate, 16) Or Not BitAND($winstate, 2) Then WinSetState($main_gui, "", @SW_HIDE) EndIf Case $GUI_EVENT_CLOSE, $idclosewin Exit EndSwitch Switch TrayGetMsg() Case $RestoreTray WinSetState($main_gui, "", @SW_RESTORE) Case $ExitTray Exit EndSwitch WEnd i will get -7 and -8 every time i click the close button after i started minimized. When i start with SW_show i will get -- and 3 vor ervery close button click $idclosewin: 3 $msg: -7 $msg: -8 $msg: -7 $msg: -8 $msg: -7 $msg: -8 $msg: -3 Link to post Share on other sites
ESPUser 0 Posted May 15, 2020 Author Share Posted May 15, 2020 Type error - should have been: When i start with SW_show i will get -7 and 3 for ervery close button click Link to post Share on other sites
Moderators Melba23 3,799 Posted May 15, 2020 Moderators Share Posted May 15, 2020 ESPUser, You are mixing GUISetState and WinSetState, which usually ends in tears. As you are dealing with your own GUI, stick with GUISetState like this: expandcollapse popup#include <GUIConstants.au3> Opt("TrayMenuMode", 3) TraySetIcon("Shell32.dll", -87) TraySetClick(9) $RestoreTray = TrayCreateItem("Show") $ExitTray = TrayCreateItem("Close") $guiname = "MyGUI" $main_gui = GUICreate($guiname, 200, 200) $idclosewin = GUICtrlCreateButton("Close", 10, 10) ConsoleWrite("$idclosewin: " & $idclosewin & @CRLF) ;GUISetState(@SW_SHOW, $main_gui) GUISetState(@SW_MINIMIZE, $main_gui) While 1 $msg = GUIGetMsg() If $msg <> 0 And $msg <> -11 Then ConsoleWrite("$msg: " & $msg & @CRLF) Switch $msg ; Let AutoIt do the work for you <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ;Case $GUI_EVENT_MINIMIZE ;$winstate = WinGetState($main_gui) ;If BitAND($winstate, $WIN_STATE_MINIMIZED) Or Not BitAND($winstate, $WIN_STATE_VISIBLE) Then ;GUISetState(@SW_HIDE, $main_gui) ;EndIf Case $GUI_EVENT_CLOSE, $idclosewin Exit EndSwitch Switch TrayGetMsg() Case $RestoreTray GUISetState(@SW_RESTORE, $main_gui) ; Restore the GUI <<<<<<<<<<<<<<<< GUISetState(@SW_SHOW, $main_gui) ; But the first time you have to show it as well! <<<<<<<<<<< Case $ExitTray Exit EndSwitch WEnd I have added comments to explain what I think is going on. Does it work for you too? M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to post Share on other sites
ESPUser 0 Posted May 15, 2020 Author Share Posted May 15, 2020 Thanks for the hint about wingetstate and guisetstate. Does it work -well, almost. Without the lines you commented out it starts up just fine and can be restored from the tray. The close button also works, but i can no longer minimize to tray. Any idea how to solve this? Link to post Share on other sites
ESPUser 0 Posted May 15, 2020 Author Share Posted May 15, 2020 Case $GUI_EVENT_MINIMIZE $winstate = WinGetState($main_gui) If BitAND($winstate, 16) Or Not BitAND($winstate, 2) Then WinSetState($main_gui, "", @SW_HIDE) EndIf This seems to work, thank you for finding what i did wrong. Link to post Share on other sites
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