fopetesl Posted March 23, 2017 Share Posted March 23, 2017 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. Link to comment Share on other sites More sharing options...
aa2zz6 Posted March 23, 2017 Share Posted March 23, 2017 You could try to use a HotKetSet to close it HotKeySet("{ESC}", "Terminate") Func Terminate() Exit EndFunc ;==>Terminate Link to comment Share on other sites More sharing options...
fopetesl Posted March 23, 2017 Author Share Posted March 23, 2017 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. Link to comment Share on other sites More sharing options...
aa2zz6 Posted March 23, 2017 Share Posted March 23, 2017 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 Link to comment Share on other sites More sharing options...
fopetesl Posted March 23, 2017 Author Share Posted March 23, 2017 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. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 23, 2017 Moderators Share Posted March 23, 2017 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 fopetesl 1 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
fopetesl Posted March 24, 2017 Author Share Posted March 24, 2017 Your example works a treat, M23. Thank you for the time The most powerful number in the Universe. Zero. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now