how to quit a gui

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
sbrady19
Posts: 344
Joined: 12 Apr 2018, 05:22
Location: Central Florida
Contact:

how to quit a gui

27 Jan 2024, 20:05

what do you have to do, that when you click the GUI "X", like all PC apps, the gui quits and goes away and the ICON is NOT in the HIDDEN icons window. Thanks for any help.
User avatar
submeg
Posts: 328
Joined: 14 Apr 2017, 20:39
Contact:

Re: how to quit a gui

27 Jan 2024, 20:12

From here:

Code: Select all

MyGui := Gui()
MyGui.AddText("", "Press Alt+F4 or the X button in the title bar.")
MyGui.OnEvent("Close", MyGui_Close)
MyGui_Close(thisGui) {  ; Declaring this parameter is optional.
    if MsgBox("Are you sure you want to close the GUI?",, "y/n") = "No"
        return true  ; true = 1
}
MyGui.Show
____________________________________
Check out my site, submeg.com
Connect with me on LinkedIn
Courses on AutoHotkey :ugeek:
sbrady19
Posts: 344
Joined: 12 Apr 2018, 05:22
Location: Central Florida
Contact:

Re: how to quit a gui

27 Jan 2024, 20:19

my gui is call Main
here is what I did
I dont need the reminder window
the gui window closes
the icon is still in the hidden icons window

Code: Select all

Main.OnEvent("Close", Main_Close)
Main_Close(thisGui) {  ; Declaring this parameter is optional.
    if MsgBox("Are you sure you want to close the GUI?",, "y/n") = "No"
        return true  ; true = 1
}
Main.Show
User avatar
submeg
Posts: 328
Joined: 14 Apr 2017, 20:39
Contact:

Re: how to quit a gui

27 Jan 2024, 21:31

sbrady19 wrote:
27 Jan 2024, 20:19
the icon is still in the hidden icons window
Do you mean the AHK script icon (i.e. the script is still running when you close the GUI)?

If that's the case, you just need to add an ExitApp:

Code: Select all

Main.OnEvent("Close", Main_Close)
Main_Close(thisGui) {  ; Declaring this parameter is optional.
    if MsgBox("Are you sure you want to close the GUI?",, "y/n") = "No"
        return true  ; true = 1
		ExitApp
        
}
Main.Show
____________________________________
Check out my site, submeg.com
Connect with me on LinkedIn
Courses on AutoHotkey :ugeek:
sbrady19
Posts: 344
Joined: 12 Apr 2018, 05:22
Location: Central Florida
Contact:

Re: how to quit a gui

28 Jan 2024, 10:41

there has to be more to it than that, right. Or if I put ExitApp: at the every end of the script, the app completely quits and closes. I'll get back to you.
User avatar
boiler
Posts: 17242
Joined: 21 Dec 2014, 02:44

Re: how to quit a gui

28 Jan 2024, 10:57

The system tray icon (as opposed to a taskbar icon) usually goes away when the script is closed, not when one of its windows is closed, which is why submeg suggested what he did. You can set it not to show while the script is running if you want by assigning 1 to A_IconHidden. You can restore it by assigning 0 to it.
just me
Posts: 9542
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: how to quit a gui

28 Jan 2024, 11:32

:arrow: Script Startup (the Auto-execute Thread)
The script will terminate after completing startup if it lacks hotkeys, hotstrings, visible GUIs, active timers, clipboard monitors and InputHooks, and has not called the Persistent function. Otherwise, it will stay running in an idle state, responding to events such as hotkeys, hotstrings, GUI events, custom menu items, and timers. If these conditions change after startup completes (for example, the last timer is disabled), the script may exit when the last running thread completes or the last GUI closes.
Actually, the sample posted by @submeg

Code: Select all

MyGui := Gui()
MyGui.AddText("", "Press Alt+F4 or the X button in the title bar.")
MyGui.OnEvent("Close", MyGui_Close)
MyGui_Close(thisGui) {  ; Declaring this parameter is optional.
    if MsgBox("Are you sure you want to close the GUI?",, "y/n") = "No"
        return true  ; true = 1
}
MyGui.Show
terminates the script when the Gui is closed and removes the icon from the tray.

If your script is persistent for some reason, you need ExitApp to terminate.

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: akirofe, bob65536, jsong55, pedro45_vs and 35 guests