Jump to content

[Solved] Exit closes all windows


Hest
 Share

Recommended Posts

I tried making a form with a button. The button opened another window, where I could click other buttons and so on.

But when I pres the X in the extra window, both windows closes.

I'm not sure if I open the extra window the correct way or not, but how can I prevent both windows from closing or am I doing it the wrong way?

#include <GUIConstants.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 625, 445, 193, 125)
$Button1 = GUICtrlCreateButton("Button1", 152, 72, 115, 57, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

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


        Case $Button1
            #Region ### START Koda GUI section ### Form=
$Form2 = GUICreate("Form2", 625, 445, 404, 178)
$Input1 = GUICtrlCreateInput("Input1", 56, 40, 121, 21)
$Input2 = GUICtrlCreateInput("Input2", 56, 70, 121, 21)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

    EndSwitch
WEnd

(Code is only some temporary I made to test it)

Edited by Hest
Software:Model Train Calculator (Screen)Autoit3 beginner!
Link to comment
Share on other sites

Something like this:

#include <GUIConstants.au3>

$Form1 = GUICreate("Form1", 625, 445, 193, 125)
$Button1 = GUICtrlCreateButton("Button1", 152, 72, 115, 57, 0)

$Form2 = GUICreate("Form2", 625, 445, 404, 178)
$Input1 = GUICtrlCreateInput("Input1", 56, 40, 121, 21)
$Input2 = GUICtrlCreateInput("Input2", 56, 70, 121, 21)

GUISetState(@SW_SHOW, $Form1)

While 1

    $aMsg = GUIGetMsg(1)
    Switch $aMsg[1]
        Case $Form1
            Switch $aMsg[0]
                Case $GUI_EVENT_CLOSE
                    Exit
                Case $Button1
                    GUISetState(@SW_SHOW, $Form2)
            EndSwitch
        Case $Form2
            Switch $aMsg[0]
                Case $GUI_EVENT_CLOSE
                    GUISetState(@SW_HIDE, $Form2)
            EndSwitch
    EndSwitch

WEnd

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

I tried making a form with a button. The button opened another window, where I could click other buttons and so on.

But when I pres the X in the extra window, both windows closes.

I'm not sure if I open the extra window the correct way or not, but how can I prevent both windows from closing or am I doing it the wrong way?

#include <GUIConstants.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 625, 445, 193, 125)
$Button1 = GUICtrlCreateButton("Button1", 152, 72, 115, 57, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

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


        Case $Button1
            #Region ### START Koda GUI section ### Form=
$Form2 = GUICreate("Form2", 625, 445, 404, 178)
$Input1 = GUICtrlCreateInput("Input1", 56, 40, 121, 21)
$Input2 = GUICtrlCreateInput("Input2", 56, 70, 121, 21)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

    EndSwitch
WEnd

Clicking the "X" sends the $GUI_EVENT_CLOSE message, which does Exit in your GUIGetMsg() loop.

(Code is only some temporary I made to test it)

You need to use advanced mode for GuiGetMsg() to see which window is sending it, or have another nested loop to handle the second GUI:
#include <GUIConstants.au3>

Global $Form1, $Form2, $Button1, $Button2, $Input1, $Input2, $nMsg

$Form1 = GUICreate("Form1", 625, 445, 193, 125)
$Button1 = GUICtrlCreateButton("Button1", 152, 72, 115, 57, 0)
GUISetState(@SW_SHOW)

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

        Case $Button1
            $Form2 = GUICreate("Form2", 625, 445, 404, 178)
            $Input1 = GUICtrlCreateInput("Input1", 56, 40, 121, 21)
            $Input2 = GUICtrlCreateInput("Input2", 56, 70, 121, 21)
            $Button2 = GUICtrlCreateButton("READ", 56, 100, 121, 21)
            GUISetState(@SW_SHOW)
            While 1
                $nMsg = GUIGetMsg()
                Switch $nMsg
                    Case $GUI_EVENT_CLOSE
                        GUIDelete($Form2)
                        GUISwitch($Form1)
                        ExitLoop

                    Case $Button2
                        MsgBox(64, "Read", "Input1 = " & GUICtrlRead($Input1) & @CRLF & _
                                "Input2 = " & GUICtrlRead($Input2))
                EndSwitch
            WEnd
    EndSwitch
WEnd

^_^

Edit: Curses! Out-typed by the trancexx poster bot! ;)

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

You are swearing and there could be children reading.

I'll try to keep it PG-max for the little nippers. Wouldn't want to shock any of 'em.

(Deep fry 'da noisy ones and serve 'em up wit' honey mustard dipping sauce... but not shock 'em!)

^_^

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
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...