Jump to content

Window will not close

Recommended Posts


#include <GuiConstantsEx.au3>

Opt("GUIOnEventMode", 1)  ; Change to OnEvent mode
GUISetOnEvent($GUI_EVENT_CLOSE, "OnExitScript")

GUICreate("This is a test", 500, 500)
$ExitButton = GUICtrlCreateButton("Exit", 400, 400, 80, 24)
GUICtrlSetOnEvent($ExitButton, "OnExitScript")

While 1
;End of main script

Func OnExitScript()
    MsgBox(1,"test", "OnExitScript")

Func OnExit()
    MsgBox(1,"test", "OnExit")

My GUI window will not close when I click the X in the top right of the window or when I try using Alt+F4. I have stripped this code down to the bare minimum for my example but the above code shows a window with a single Exit button. The button works but not the X in top right.


I give up, what obvious simple thing am I overlooking?

Share this post

Link to post
Share on other sites

Ugggg!!! finally figured it out. You can NOT perform GUISetOnEvent($GUI_EVENT_CLOSE,  "OnExitScript") BEFORE you create the GUI. Moved that line below GUICreate and it worked.

Damn I spent forever trying to figure that out!!!

Share this post

Link to post
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


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.