Jump to content

Recommended Posts

Posted

When you run this script, you will get a window, then click a button, then another window.

When you close the second window (win2) the the first one (win1) closes as well, how can I get win1 keep running?

#include <GUIConstants.au3>

$win1 = GUICreate("Form1", 436, 96, 193, 125)
$win1Button1 = GUICtrlCreateButton("Click meh!", 40, 16, 353, 57, 0)
GUICtrlSetFont(-1, 16, 400, 0, "Tahoma")
GUISetState(@SW_SHOW)

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

        Case $win1Button1
            #include <GUIConstants.au3>

            $win2 = GUICreate("win2", 330, 225, 193, 125)
            $win2Label1 = GUICtrlCreateLabel("a new window!", 88, 16, 131, 27)
            GUICtrlSetFont(-1, 14, 400, 0, "Tahoma")
            $win2Label2 = GUICtrlCreateLabel("=)", 96, 40, 111, 120)
            GUICtrlSetFont(-1, 72, 400, 0, "Tahoma")
            $win2Label3 = GUICtrlCreateLabel("now close meh :S", 64, 184, 170, 29)
            GUICtrlSetFont(-1, 16, 400, 0, "Tahoma")
            GUISetState(@SW_SHOW)

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

                EndSwitch
            WEnd

    EndSwitch
WEnd
Posted

You could use GUIDelete

Thanks! Works fine, thanks :)

Remember, you only need to include GUIConstants.au3 once

Yeah, I was abit lazy in that, was a quick making :(

Thanks guys, quick answer :D

Posted (edited)

EDIT: Didn't see the above reply.

#include <GUIConstants.au3>

$win1 = GUICreate("Form1", 436, 96, 193, 125)
$win1Button1 = GUICtrlCreateButton("Click meh!", 40, 16, 353, 57, 0)
GUICtrlSetFont(-1, 16, 400, 0, "Tahoma")
GUISetState(@SW_SHOW)

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

        Case $win1Button1

            $win2 = GUICreate("win2", 330, 225, 193, 125)
            $win2Label1 = GUICtrlCreateLabel("a new window!", 88, 16, 131, 27)
            GUICtrlSetFont(-1, 14, 400, 0, "Tahoma")
            $win2Label2 = GUICtrlCreateLabel("=)", 96, 40, 111, 120)
            GUICtrlSetFont(-1, 72, 400, 0, "Tahoma")
            $win2Label3 = GUICtrlCreateLabel("now close meh :S", 64, 184, 170, 29)
            GUICtrlSetFont(-1, 16, 400, 0, "Tahoma")
            GUISetState(@SW_SHOW)
            GUISwitch($win2)

            While 1
                $nMsg2 = GUIGetMsg()
                Switch $nMsg2
                Case $GUI_EVENT_CLOSE
                    GUIDelete($win2)
                    GUISwitch($win1)
                    ExitLoop
                    
                EndSwitch
            WEnd

    EndSwitch
WEnd

:)

Edited by cppman
Posted

Nice with the GUISwitch($win1) I usely set the new GUI in a function and then use return like this:

Don't what is best?

#include <GUIConstants.au3>

$win1 = GUICreate("Form1", 436, 96, 193, 125)
$win1Button1 = GUICtrlCreateButton("Click meh!", 40, 16, 353, 57, 0)
GUICtrlSetFont(-1, 16, 400, 0, "Tahoma")
GUISetState(@SW_SHOW)

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

        Case $win1Button1
            _window2()

    EndSwitch
WEnd

Func _window2()
            
    $win2 = GUICreate("win2", 330, 225, 193, 125)
    $win2Label1 = GUICtrlCreateLabel("a new window!", 88, 16, 131, 27)
    GUICtrlSetFont(-1, 14, 400, 0, "Tahoma")
    $win2Label2 = GUICtrlCreateLabel("=)", 96, 40, 111, 120)
    GUICtrlSetFont(-1, 72, 400, 0, "Tahoma")
    $win2Label3 = GUICtrlCreateLabel("now close meh :S", 64, 184, 170, 29)
    GUICtrlSetFont(-1, 16, 400, 0, "Tahoma")
    GUISetState(@SW_SHOW)

    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                GUIDelete($win2)
                Return

        EndSwitch
    WEnd
EndFunc

Regards

Posted

That wasnt so bad, it was actually a really good solution.

Then you get more control over the mainframe.

Since you dont got the

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

        Case $win1Button1
            ; Forever with code

    EndSwitch
WEnd

so if more buttons, notify stuff or what ever you guys call it, then I whould go for that func solution :)

Posted

so if more buttons, notify stuff or what ever you guys call it, then I whould go for that func solution :)

Yes, Also look in the help file for GUISwitch()

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

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
×
×
  • Create New...