Jump to content

Multiple GUI's


Recommended Posts

Hi,

I wonder if it's possible to have 2, or 3 GUI's running at the same time? If possible, say, now, I want to have a label on the second, or third GUI, how can I do that?

As I can see, we cannot specify the GUI Handle in the GUICtrlCreateLabel function, to tell which GUI this label should be create on. Is there a work around or something? >_<

GUICtrlCreateLabel ( "text", left, top [, width [, height [, style [, exStyle]]]] )

I'm thinking about calling another .exe programme, which will create a GUI when loaded. but it's not convenient at all. Since, if I want to have 2 more GUI's, I have to call that .exe twice. And if I want to have 5 more GUI's, then I have to call it 5 times.. =((

So, I wonder if I can just create more than 1 GUI using just one applicant?

Thanks guys a lot in advace. :(

Edited by eEniquEe
Link to comment
Share on other sites

First off, yes, you can have multiple gui's. If you create a control, it will be created on the last created gui. To change the gui that the script works with you can use guiswitch.

Edit: Why is this in the general help and support forum?

Edited by Hawkwing

The Wheel of Time turns, and Ages come and pass, leaving memories that become legend. Legend fades to myth, and even myth is long forgotten when the Age that gave it birth comes again.

Link to comment
Share on other sites

This is one way:

$GUI_1 = GUICreate("GUI #1", 200, 100, 100, 100)
$Button_1 = GUICtrlCreateButton("Button #1", 50, 30, 100)
GUISetState()

$GUI_2 = GUICreate("GUI #2", 200, 100, 200, 200)
$Button_2 = GUICtrlCreateButton("Button #2", 50, 30, 100)
GUISetState()

$GUI_3 = GUICreate("GUI #3", 200, 100, 300, 300)
$Button_3 = GUICtrlCreateButton("Button #3", 50, 30, 100)
GUISetState()

While 1
    $nMsg = GUIGetMsg()
    Select
    Case $nMsg = -3 ;$GUI_EVENT_CLOSE
        Exit
    Case $nMsg = $Button_1
        MsgBox(64, Default, "Button 1 clicked!")
    Case $nMsg = $Button_2
        MsgBox(64, Default, "Button 2 clicked!")
    Case $nMsg = $Button_3
        MsgBox(64, Default, "Button 3 clicked!")
    EndSelect
WEnd

But the script exits when you click ANY [X].

AlmarM

Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

Link to comment
Share on other sites

You could also use the advanced switch of GUIGetMsg...

$gui1 = GUICreate ("", 200, 200, 100, 100)
GUISetState ()

$gui2 = GUICreate("", 200, 200, 350, 100, Default, Default, $gui1)
$label1 = GUICtrlCreateLabel ("This is a cool label!", 10, 10, 180, 180)
GUISetState()

$gui3 = GUICreate("", 200, 200, 600, 100, Default, Default, $gui1)
$button1 = GUICtrlCreateButton ("This is a button!", 10, 10, 180)
GUISetState()

While 1
    $nMsg = GUIGetMsg (1)
    Switch $nMsg[0]
        Case -3;$GUI_EVENT_CLOSE
            Switch $nMsg[1]
                Case $gui1
                    Exit
                Case $gui2
                    MsgBox (0, "", "OH NO!  USE THE BLANK GUI TO THE LEFT!")
                Case $gui3
                    ToolTip ("We will not closing using this GUI. Just use the one to the far left")
            EndSwitch
        Case $button1
            $clr = Hex(Random (0, 0xFFFFFF),6)
            GUISetBkColor ($clr,$gui1)
            GUICtrlSetData ($label1, GUICtrlRead ($label1) & @CRLF & $clr)
    EndSwitch
WEnd
Link to comment
Share on other sites

First off, yes, you can have multiple gui's. If you create a control, it will be created on the last created gui. To change the gui that the script works with you can use guiswitch.

Edit: Why is this in the general help and support forum?

Errr.. because I thought I needed some help. So, I just post it over here. :( Well, I wonder what board my thread should belong to?

This is one way:

$GUI_1 = GUICreate("GUI #1", 200, 100, 100, 100)
$Button_1 = GUICtrlCreateButton("Button #1", 50, 30, 100)
GUISetState()

$GUI_2 = GUICreate("GUI #2", 200, 100, 200, 200)
$Button_2 = GUICtrlCreateButton("Button #2", 50, 30, 100)
GUISetState()

$GUI_3 = GUICreate("GUI #3", 200, 100, 300, 300)
$Button_3 = GUICtrlCreateButton("Button #3", 50, 30, 100)
GUISetState()

While 1
    $nMsg = GUIGetMsg()
    Select
    Case $nMsg = -3 ;$GUI_EVENT_CLOSE
        Exit
    Case $nMsg = $Button_1
        MsgBox(64, Default, "Button 1 clicked!")
    Case $nMsg = $Button_2
        MsgBox(64, Default, "Button 2 clicked!")
    Case $nMsg = $Button_3
        MsgBox(64, Default, "Button 3 clicked!")
    EndSelect
WEnd

But the script exits when you click ANY [X].

AlmarM

You could also use the advanced switch of GUIGetMsg...

$gui1 = GUICreate ("", 200, 200, 100, 100)
GUISetState ()

$gui2 = GUICreate("", 200, 200, 350, 100, Default, Default, $gui1)
$label1 = GUICtrlCreateLabel ("This is a cool label!", 10, 10, 180, 180)
GUISetState()

$gui3 = GUICreate("", 200, 200, 600, 100, Default, Default, $gui1)
$button1 = GUICtrlCreateButton ("This is a button!", 10, 10, 180)
GUISetState()

While 1
    $nMsg = GUIGetMsg (1)
    Switch $nMsg[0]
        Case -3;$GUI_EVENT_CLOSE
            Switch $nMsg[1]
                Case $gui1
                    Exit
                Case $gui2
                    MsgBox (0, "", "OH NO!  USE THE BLANK GUI TO THE LEFT!")
                Case $gui3
                    ToolTip ("We will not closing using this GUI. Just use the one to the far left")
            EndSwitch
        Case $button1
            $clr = Hex(Random (0, 0xFFFFFF),6)
            GUISetBkColor ($clr,$gui1)
            GUICtrlSetData ($label1, GUICtrlRead ($label1) & @CRLF & $clr)
    EndSwitch
WEnd

Thanks BrettF, and AlmarM for taking your precious time to give me 2 nice, and easy-to-understand examples. >_<

Thanks very much. :(

Link to comment
Share on other sites

Errr.. because I thought I needed some help. So, I just post it over here. >_< Well, I wonder what board my thread should belong to?

There's a seperate GUI help and support forum.

http://www.autoitscript.com/forum/index.php?showforum=10

The Wheel of Time turns, and Ages come and pass, leaving memories that become legend. Legend fades to myth, and even myth is long forgotten when the Age that gave it birth comes again.

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