texan

Window will not close

2 posts in this topic

#include <GuiConstantsEx.au3>

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

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

While 1
    Sleep(1000)
WEnd
;End of main script
;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

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

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

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