DigDeep Posted March 16, 2018 Posted March 16, 2018 Hi, I want to exit the GUI from 3 locations. $GUI_EVENT_CLOSE = GUI Form Close button $close = GUI Close custom button $idExit = Tray menu close button I took the Tray menu example inside a text GUI Form but it's only the Tray menu which closes. $GUI_EVENT_CLOSE and $close do not do anything. Can anyone help please? expandcollapse popup#NoTrayIcon #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <MsgBoxConstants.au3> #include <StringConstants.au3> #include <TrayConstants.au3> ; Required for the $TRAY_ICONSTATE_SHOW constant. Global $close = 9999 Global $idExit = 9999 #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 240, 254, 438, 144) $Label1 = GUICtrlCreateLabel("Test Lable 1", 56, 40, 127, 33, $SS_CENTER) $Label2 = GUICtrlCreateLabel("Test Lable 2", 56, 120, 127, 41, $SS_CENTER) $close = GUICtrlCreateButton("Close", 88, 208, 75, 25) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### Opt("TrayMenuMode", 3) ; The default tray menu items will not be shown and items are not checked when selected. These are options 1 and 2 for TrayMenuMode. SystemTrayMenu() ; System Tray Menu While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE, $close, $idExit Exit EndSwitch WEnd Func SystemTrayMenu() ; System Tray Menu Local $iSettings = TrayCreateMenu("Settings") ; Create a tray menu sub menu with two sub items. Local $iDisplay = TrayCreateItem("Display", $iSettings) Local $iPrinter = TrayCreateItem("Printer", $iSettings) TrayCreateItem("") ; Create a separator line. Local $idAbout = TrayCreateItem("About") TrayCreateItem("") ; Create a separator line. Local $idExit = TrayCreateItem("Exit") TraySetState($TRAY_ICONSTATE_SHOW) ; Show the tray menu. While 1 Switch TrayGetMsg() Case $idAbout ; Display a message box about the AutoIt version and installation path of the AutoIt executable. MsgBox($MB_SYSTEMMODAL, "", "AutoIt tray menu example." & @CRLF & @CRLF & _ "Version: " & @AutoItVersion & @CRLF & _ "Install Path: " & StringLeft(@AutoItExe, StringInStr(@AutoItExe, "\", $STR_NOCASESENSEBASIC, -1) - 1)) ; Find the folder of a full path. Case $iDisplay, $iPrinter MsgBox($MB_SYSTEMMODAL, "", "A sub menu item was selected from the tray menu.") Case $idExit ; Exit the loop. ExitLoop EndSwitch WEnd EndFunc ;==>Example
Moderators Melba23 Posted March 16, 2018 Moderators Posted March 16, 2018 DigDeep, You need to have just the one idle loop: expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <MsgBoxConstants.au3> #include <TrayConstants.au3> ; Required for the $TRAY_ICONSTATE_SHOW constant. ; Make tray items global in scope as they are created inside a function Global $iDisplay, $iPrinter, $idAbout, $idExit $Form1 = GUICreate("Form1", 240, 254, 438, 144) $Label1 = GUICtrlCreateLabel("Test Lable 1", 56, 40, 127, 33, $SS_CENTER) $Label2 = GUICtrlCreateLabel("Test Lable 2", 56, 120, 127, 41, $SS_CENTER) $close = GUICtrlCreateButton("Close", 88, 208, 75, 25) GUISetState(@SW_SHOW) Opt("TrayMenuMode", 3) ; The default tray menu items will not be shown and items are not checked when selected. These are options 1 and 2 for TrayMenuMode. SystemTrayMenu() ; System Tray Menu While 1 ; Check GUI events Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $close Exit EndSwitch ; Check tray events Switch TrayGetMsg() Case $idAbout ; Display a message box about the AutoIt version and installation path of the AutoIt executable. MsgBox($MB_SYSTEMMODAL, "", "AutoIt tray menu example." & @CRLF & @CRLF & _ "Version: " & @AutoItVersion & @CRLF & _ "Install Path: " & StringLeft(@AutoItExe, StringInStr(@AutoItExe, "\", $STR_NOCASESENSEBASIC, -1) - 1)) ; Find the folder of a full path. Case $iDisplay, $iPrinter MsgBox($MB_SYSTEMMODAL, "", "A sub menu item was selected from the tray menu.") Case $idExit ; Exit Exit EndSwitch WEnd Func SystemTrayMenu() ; System Tray Menu Local $iSettings = TrayCreateMenu("Settings") ; Create a tray menu sub menu with two sub items. $iDisplay = TrayCreateItem("Display", $iSettings) $iPrinter = TrayCreateItem("Printer", $iSettings) TrayCreateItem("") ; Create a separator line. $idAbout = TrayCreateItem("About") TrayCreateItem("") ; Create a separator line. $idExit = TrayCreateItem("Exit") TraySetState($TRAY_ICONSTATE_SHOW) ; Show the tray menu. ; No loop here! EndFunc ;==>SystemTrayMenu M23 DigDeep 1 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
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