Jump to content

How to close my GUI without exiting my script


Noob
 Share

Recommended Posts

Hi Guys,

I've spent the better part of today trying to figure out how to close my GUI without exiting my script. I read the help, I searched the Forum, but I'm just too new to this to get to the bottom of this myself.

Here is the simplification of my code. I have a script that does a variety of things, one of which should be a function which will create a GUI. When I click the close button in the top right corner of the GUI, I want the GUI to close, but I don't want the script to exit.

Any help would be greatly appreciated.

HotKeySet("{F2}", "my_gui")

While 1
    $msg = GUIGetMsg()
    If $msg = -3 Then Exit
    Sleep(100) 
WEnd

Func my_gui()
GUICreate("My 1st GUI :-)")
GUISetState ()
EndFunc
Link to comment
Share on other sites

Note that if you press F2 multiple times you will get multiple GUIs. I modified the script a bit, so that if press close

the GUI it will be hidden, while you can make it visible again by pressing F2. I also made it impossible to press F2

while the GUI is visible, avoiding having multiple GUIs at the same time. Kind of guessing what you want, but it

might be of some help.

GUICreate("My 1st GUI :-)") ; Create it once in the beginning without showing it
HotKeySet("{F2}", "my_gui")

While 1
    $msg = GUIGetMsg()
    
    If $msg = -3 Then
        GUISetState(@SW_HIDE)       ; Hide GUI
        HotKeySet("{F2}", "my_gui") ; Enable hotkey
    EndIf
WEnd

Func my_gui()
    GUISetState(@SW_SHOW)   ; Show GUI
    HotKeySet("{F2}")       ; Disable hotkey
EndFunc
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...