Jump to content

Gui window can not be closed ?


Ericlee
 Share

Recommended Posts

all the function of this script is ok except the GUI window. it can not be closed when click the close bottom, and i don't know what's the problem?

the code is

#include <GUIConstantsEx.au3>

Opt('MustDeclareVars', 1)

HotKeySet('#a','Example')

While 1

Sleep(100)

WEnd

Func Example()

Local $Button_1, $Button_2, $msg

GUICreate("My GUI Button")

Opt("GUICoordMode", 2)

$Button_1 = GUICtrlCreateButton("Button 1", 10, 30, 100)

$Button_2 = GUICtrlCreateButton("Button 2", 0, -1)

GUISetState()

While 1

$msg = GUIGetMsg()

Select

Case $msg = $GUI_EVENT_CLOSE

ExitLoop

Case $msg = $Button_1

MsgBox(0, 'Testing', 'Button 1 was pressed')

Case $msg = $Button_2

MsgBox(0, 'Testing', 'Button 2 was pressed')

EndSelect

WEnd

EndFunc

Edited by Ericlee
Link to comment
Share on other sites

You code doesn't have anything in it that closes the GUI, exiting the loop just jumps out of the loop, and then goes back to the While...Wend loop waiting for you to hit the Win + a keys again, leaving the window open. If you want the GUI_EVENT_CLOSE to exit the program you need to change the ExitLoop command to Exit. If you want to close the GUI and have the program wait until you hit the Win + a key again, running in the background the whole time, you should put the command GUIDelete() before the ExitLoop.

This example leaves the program running in the background until you hit Win + a again, but kills the GUI:

Func Example()
    Local $Button_1, $Button_2, $msg
    GUICreate("My GUI Button")
    Opt("GUICoordMode", 2)
    $Button_1 = GUICtrlCreateButton("Button 1", 10, 30, 100)
    $Button_2 = GUICtrlCreateButton("Button 2", 0, -1)
    GUISetState()
    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                GUIDelete() ; <<<<<<<<<<<<<<<<< Add this line
                ExitLoop
            Case $msg = $Button_1
                MsgBox(0, 'Testing', 'Button 1 was pressed')
            Case $msg = $Button_2
                MsgBox(0, 'Testing', 'Button 2 was pressed')
        EndSelect
    WEnd
EndFunc

This example will close the program when you close the GUI:

Func Example()
    Local $Button_1, $Button_2, $msg
    GUICreate("My GUI Button")
    Opt("GUICoordMode", 2)
    $Button_1 = GUICtrlCreateButton("Button 1", 10, 30, 100)
    $Button_2 = GUICtrlCreateButton("Button 2", 0, -1)
    GUISetState()
    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                Exit ; <<<<<<<<<<<<<<<<<<<< Change this line
            Case $msg = $Button_1
                MsgBox(0, 'Testing', 'Button 1 was pressed')
            Case $msg = $Button_2
                MsgBox(0, 'Testing', 'Button 2 was pressed')
        EndSelect
    WEnd
EndFunc

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

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...