Sign in to follow this  
Followers 0
newbiescripter

How to close one window without closing whole script in GUI?

7 posts in this topic

Hello

when I try run the example and press the about button the About window pops up just like it should do, but when I then close it I only want that to be closed and not the main windows. How do I do that?

I've tried the OnAutoItExit () but I can't make it work.

Hope you can help me :)

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <ButtonConstants.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Main Window", 217, 132, 406, 212)
$MenuItem1 = GUICtrlCreateMenuItem("About",-1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $MenuItem1
            _About()
    EndSwitch
WEnd

Func _About()

#Region ### START Koda GUI section ### Form=
$Form2 = GUICreate("About", 178, 166, 366, 246)
GUISetIcon("D:\006.ico")
$GroupBox1 = GUICtrlCreateGroup("", 8, 8, 161, 105)
$Label1 = GUICtrlCreateLabel("Hello", 16, 32, 132, 68)
GUICtrlSetFont(-1, 40, 400, 0, "MS Sans Serif")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Button1 = GUICtrlCreateButton("&OK", 48, 128, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            Exit
    EndSwitch
WEnd

EndFunc;==> _About()

Thanks

Regards

Share this post


Link to post
Share on other sites



#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <ButtonConstants.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Main Window", 217, 132, 406, 212)
$MenuItem1 = GUICtrlCreateMenuItem("About",-1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $MenuItem1
            _About()
    EndSwitch
WEnd

Func _About()

#Region ### START Koda GUI section ### Form=
$Form2 = GUICreate("About", 178, 166, 366, 246)
GUISetIcon("D:\006.ico")
$GroupBox1 = GUICtrlCreateGroup("", 8, 8, 161, 105)
$Label1 = GUICtrlCreateLabel("Hello", 16, 32, 132, 68)
GUICtrlSetFont(-1, 40, 400, 0, "MS Sans Serif")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Button1 = GUICtrlCreateButton("&OK", 48, 128, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            GUIDelete($Form2)
    EndSwitch
WEnd

EndFunc;==> _About()



Get Beta versions Here Get latest SciTE editor Here AutoIt 1-2-3 by Valuater - A great starting point.

Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

Share this post


Link to post
Share on other sites

So simple :) Thanks..

Then I've another little question.. How do you put your code into this forum with colors? I can't I use the [Co de] and [/ Co de]

Share this post


Link to post
Share on other sites

So simple :) Thanks..

Then I've another little question.. How do you put your code into this forum with colors? I can't I use the [Co de] and [/ Co de]

[ autoit ] [ /autoit ] without the spaces


Get Beta versions Here Get latest SciTE editor Here AutoIt 1-2-3 by Valuater - A great starting point.

Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

Share this post


Link to post
Share on other sites

Correction of BigDod's solution:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <ButtonConstants.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Main Window", 217, 132, 406, 212)
$MenuItem1 = GUICtrlCreateMenuItem("About", -1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $MenuItem1
            _About()
    EndSwitch
WEnd

Func _About()
    #Region ### START Koda GUI section ### Form=
    $Form2 = GUICreate("About", 178, 166, 366, 246)
    GUISetIcon("D:\006.ico")
    $GroupBox1 = GUICtrlCreateGroup("", 8, 8, 161, 105)
    $Label1 = GUICtrlCreateLabel("Hello", 16, 32, 132, 68)
    GUICtrlSetFont(-1, 40, 400, 0, "MS Sans Serif")
    GUICtrlCreateGroup("", -99, -99, 1, 1)
    $Button1 = GUICtrlCreateButton("&OK", 48, 128, 75, 25)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

    While 1
        $nMsg = GUIGetMsg(1) ; here are messages also from Form1 so you must distinguish them (here ignore them)
        Select
            Case ($nMsg[0] = $GUI_EVENT_CLOSE Or $nMsg[0] = $Button1) And $nMsg[1] = $Form2
                GUIDelete($Form2)
                Return
        EndSelect
    WEnd
EndFunc   ;==>_About

Share this post


Link to post
Share on other sites

Thanks I was in too much of a hurry



Get Beta versions Here Get latest SciTE editor Here AutoIt 1-2-3 by Valuater - A great starting point.

Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

Share this post


Link to post
Share on other sites

Thanks I now use it with return and thats works fine :) before the main window was useless until restart.

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