Jump to content

Using multiple Exit locations in GUI


DigDeep
 Share

Recommended Posts

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?

#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

 

Link to comment
Share on other sites

  • Moderators

DigDeep,

You need to have just the one idle loop:

#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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...