Sign in to follow this  
Followers 0
Queener

Exit Button

7 posts in this topic

#1 ·  Posted (edited)

I see there's a request of help for closing the program because clicking X doesn't take effects. Thread seems old so I didn't want to bump it. Instead I post what might help them here. I've been playing around and it's not easy, but with an Exit button; it worked. Hopefully this will help most users:

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Include <GuiButton.au3>

$TESTExit = GUICreate("EXITTest",275,250,-1,-1,-1,-1)
$Button = GUICtrlCreateButton("Exit",150,20,100,24,-1,-1)
GUISetState(@SW_SHOW,$TESTEXIT)

Func TestExit()
Exit
EndFunc

While 1
Switch GUIGetMsg()
     Case $GUI_EVENT_CLOSE
     Case $Button

     TestExit()
EndSwitch
WEnd

I know an exit button is not a good practice, but hopefully someone will find it useful. In addition, professional can help out on how to make the X effective.

Edited by asianqueen

Msgbox(0, "Hate", "Just hate it when I post a question and find my own answer after a couple tries. But if I don't post the question, I can't seem to resolve it at all.")

Share this post


Link to post
Share on other sites



asianqueen,

I see there's a request of help for closing the program because clicking X doesn't take effects

And you think that script is going to help? :huh:

Your script as posted does not close on [X] because you do not tell it to do anything on receipt of the $GUI_EVENT_CLOSE event. If you do tell it what to do then both the [X] and the button work just fine:

#include <GUIConstantsEx.au3>

$TESTExit = GUICreate("EXITTest", 275, 250)
$Button = GUICtrlCreateButton("Exit", 150, 20, 100, 24)
GUISetState(@SW_SHOW, $TESTExit)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE, $Button
            Exit
    EndSwitch
WEnd

And you can see that there is a lot less of the script as most of the original was completely unnecessary. :)

I do not want to put you off from tryin gto help, but please try to post things which have some value rather then suggesting that the only way to exit a GUI is to use a button rather then the [X]. ;)

M23

P.S. If you want to link to the thread in question we can perhaps discuss why the [X] did not work in that case either. :)


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

#3 ·  Posted (edited)

very funny, I tried that earlier and it didn't want to work on me. Copying paste your code works... o:)

if you don't mind; I can help link the old thread to this post, but as I say; the thread seems old and do not want to bump.

I see my own problem...

I placed my Exit after Case $Button to do something else rather than after Event close.

Edited by asianqueen

Msgbox(0, "Hate", "Just hate it when I post a question and find my own answer after a couple tries. But if I don't post the question, I can't seem to resolve it at all.")

Share this post


Link to post
Share on other sites

asianqueen,

I placed my Exit after Case $Button to do something else rather than after Event close

Correct. You could also do this: ;)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
                ContinueCase
        Case $Button
                Exit
    EndSwitch
WEnd

I quite agree that you should not bump the old thread, but if you copy/paste the URL we can easily take a look and see what the problem was in that case. :)

M23


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

Each to their own I guess, but I much prefer an EXIT button .... providing it's well placed and large enough.

Of course, I also provide the usual 'X' too .... sometimes differentiating what each method does ... on top of exiting - save settings or cleaning up or run something on exit, etc.

Generally, I heartily dislike programs that don't provide a decent EXIT button.

Aiming for little things all the time has a way of annoying me.

You are also unlikely to click the wrong 'X' ... like happens when several windows get overlayed and you are in a hurry.


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Share this post


Link to post
Share on other sites

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
$TESTExit = GUICreate("EXITTest", 275, 250, -1, -1, BitOR($WS_CAPTION, $WS_SYSMENU))
$AltF4 = GUICtrlCreateLabel("Press ALT+F4 to exit", 10, 210)
$ContextMenu = GUICtrlCreateContextMenu()
$ContextMenuExit = GUICtrlCreateMenuItem("Exit", $ContextMenu)
$FileMenu = GUICtrlCreateMenu("&File")
$FileExit = GUICtrlCreateMenuItem("Exit", $FileMenu)
$Button = GUICtrlCreateButton("Exit", 150, 20, 100, 24)
GUISetState(@SW_SHOW, $TESTExit)
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE, $Button, $FileExit, $ContextMenuExit
Exit
     EndSwitch
WEnd

That's 6 ways to exit :P

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
Sign in to follow this  
Followers 0