fopetesl

Close only current running GUI

7 posts in this topic

#1 ·  Posted

I cannot 'escape' current GUI using 'X' without closing script.

I've (re)read other topics but none of the options will work.

First take this

#include <GUIConstantsEx.au3>

$hGUI = GUICreate("Test", 500, 500)

$hCombo = GUICtrlCreateCombo("", 10, 10, 200, 20)
GUICtrlSetData(-1, "Energy Star|myNoSleep")

GUISetState()

$sCurrCombo = ""

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hCombo
            If GUICtrlRead($hCombo) <> $sCurrCombo Then
                $sCurrCombo = GUICtrlRead($hCombo)
                MsgBox(0, "Choice", $sCurrCombo)
            EndIf
    EndSwitch

WEnd

I tried this

#include <GUIConstantsEx.au3>

$hGUI = GUICreate("Test", 500, 500)

$hCombo = GUICtrlCreateCombo("", 10, 10, 200, 20)
GUICtrlSetData(-1, "Energy Star|myNoSleep")

GUISetState()

$sCurrCombo = ""

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $hCombo
            If GUICtrlRead($hCombo) <> $sCurrCombo Then
                $sCurrCombo = GUICtrlRead($hCombo)
                MsgBox(0, "Choice", $sCurrCombo)
            EndIf
            GUIDelete
    EndSwitch

WEnd

and this

#include <GUIConstantsEx.au3>

$hGUI = GUICreate("Test", 500, 500)

$hCombo = GUICtrlCreateCombo("", 10, 10, 200, 20)
GUICtrlSetData(-1, "Energy Star|myNoSleep")

GUISetState()

$sCurrCombo = ""

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hCombo
            If GUICtrlRead($hCombo) <> $sCurrCombo Then
                $sCurrCombo = GUICtrlRead($hCombo)
                MsgBox(0, "Choice", $sCurrCombo)
            EndIf
    EndSwitch
   GUIDelete
WEnd

sorry 'Exit' should read ExitLoop above. (senior moment)

All three scripts close the whole script, which is getting big, not just the "Test" GUI.


The most powerful number in the Universe.  Zero.

Share this post


Link to post
Share on other sites



#2 ·  Posted

You could try to use a HotKetSet to close it

HotKeySet("{ESC}", "Terminate")

Func Terminate()
    Exit
EndFunc   ;==>Terminate

 

Share this post


Link to post
Share on other sites

#3 ·  Posted

3 minutes ago, aa2zz6 said:

You could try to use a HotKetSet to close it

HotKeySet("{ESC}", "Terminate")

Func Terminate()
    Exit
EndFunc   ;==>Terminate

 

Need hand holding here, aa2zz6. You're talking to a novice :)

Why do I need an extra function? Can I not incorporate into the existing script.

You also appear to be indicating the "Esc" key rather than the 'X' icon to close the GUI.

 


The most powerful number in the Universe.  Zero.

Share this post


Link to post
Share on other sites

#4 ·  Posted

It's another way to exit the script. Here is a link to your solution for getting the close button to work. Matt's solution is what you're looking at below 

 

Opt('MustDeclareVars', 1)

#include<GUIConstantsEx.au3>

GUICreate("Test")

Bye()

Func Bye()
    Local $msg
    GUISetState()
    While 1
        $msg = GUIGetMsg()
        If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    WEnd
EndFunc   ;==>Bye

 

 

Share this post


Link to post
Share on other sites

#5 ·  Posted

7 minutes ago, aa2zz6 said:

It's another way to exit the script. Here is a link to your solution for getting the close button to work. Matt's solution is what you're looking at below 

 

Opt('MustDeclareVars', 1)

#include<GUIConstantsEx.au3>

GUICreate("Test")

Bye()

Func Bye()
    Local $msg
    GUISetState()
    While 1
        $msg = GUIGetMsg()
        If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    WEnd
EndFunc   ;==>Bye

 

 

OK, call me Mr.Thicko but why do I need to have a function?

If that's the only answer I'll go with it but I cannot see why at least one of my examples doesn't work without a function call.


The most powerful number in the Universe.  Zero.

Share this post


Link to post
Share on other sites

#6 ·  Posted

fopetesl,

You cannot "escape" the GUI and keep the script running if there is no script to run. Clicking the [X] sends a $GUI_EVENT_CLOSE message and looking at your snippets:

Case $GUI_EVENT_CLOSE
            Exit ; You specifically ask the script to end
Case $GUI_EVENT_CLOSE
            ExitLoop ; But once the loop is ended there is no further script to run

What you need to do is just delete the GUI:

#include <GUIConstantsEx.au3>

$hGUI = GUICreate("Test", 500, 500)

$hCombo = GUICtrlCreateCombo("", 10, 10, 200, 20)
GUICtrlSetData(-1, "Energy Star|myNoSleep")

GUISetState()

$sCurrCombo = ""

$nBegin = TimerInit()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            GUIDelete($hGUI)
        Case $hCombo
            If GUICtrlRead($hCombo) <> $sCurrCombo Then
                $sCurrCombo = GUICtrlRead($hCombo)
                MsgBox(0, "Choice", $sCurrCombo)
            EndIf
    EndSwitch

    ; Just to prove the script is still running
    If TimerDiff($nBegin) > 1000 Then
        ConsoleWrite("Script running at " & @SEC & @CRLF)
        $nBegin = TimerInit()
    EndIf

WEnd

M23

1 person likes this

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

#7 ·  Posted

Your example works a treat, M23.

Thank you for the time :)

 


The most powerful number in the Universe.  Zero.

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