Jump to content

GUISetState() for two GUIs?


faldo
 Share

Recommended Posts

I'm having some trouble with the GUISetState() function. Even though it has a WinHandle parameter it seems only the last GUI that was created can be "Set" to whatever state <_<

IE:

#include <GUIConstants.au3>

GUICreate("My GUI1", 200, 200, 100, 100)
$Button1 = GUICtrlCreateButton("Button 1", 50, 50)
GUISetState (@SW_SHOW)

GUICreate("My GUI2", 200, 200, 320, 100)
$Button2 =GUICtrlCreateButton("Button 2", 50, 50)
GUISetState (@SW_SHOW)

While 1
    $msg = GUIGetMsg()
    If $msg = $Button1 then GUISetState (@SW_Hide, "My GUI1")
    If $msg = $Button2 then GUISetState (@SW_Hide, "My GUI2")
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
Wend
Link to comment
Share on other sites

I'm having some trouble with the GUISetState() function. Even though it has a WinHandle parameter it seems only the last GUI that was created can be "Set" to whatever state <_<

IE:

#include <GUIConstants.au3>

GUICreate("My GUI1", 200, 200, 100, 100)
$Button1 = GUICtrlCreateButton("Button 1", 50, 50)
GUISetState (@SW_SHOW)

GUICreate("My GUI2", 200, 200, 320, 100)
$Button2 =GUICtrlCreateButton("Button 2", 50, 50)
GUISetState (@SW_SHOW)

While 1
    $msg = GUIGetMsg()
    If $msg = $Button1 then GUISetState (@SW_Hide, "My GUI1")
    If $msg = $Button2 then GUISetState (@SW_Hide, "My GUI2")
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
Wend

I haven't used it myself all that much, but I believe what you're looking for is GUISwitch()

#include <GUIConstants.au3>

$GUI1 = GUICreate("My GUI1", 200, 200, 100, 100)
$Button1 = GUICtrlCreateButton("Button 1", 50, 50)
GUISetState (@SW_SHOW)

$GUI2 = GUICreate("My GUI2", 200, 200, 320, 100)
$Button2 =GUICtrlCreateButton("Button 2", 50, 50)
GUISetState (@SW_SHOW)

While 1
    $msg = GUIGetMsg()
    If $msg = $Button1 then
        GUISwitch($GUI1)
        GUISetState (@SW_Hide, "My GUI1")
    EndIf
    
    If $msg = $Button2 then
        GUISwitch($GUI2)
        GUISetState (@SW_Hide, "My GUI2")
    EndIf
    
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
Wend

- MoChr(77)& Chr(97)& Chr(100)& Chr(101)& Chr(32)& Chr(121)& Chr(97)& Chr(32)& Chr(108)& Chr(111)& Chr(111)& Chr(107)-------I've told you 100,000 times not to exaggerate!-------Don't make me hit you with my cigarette hand...-------My scripts:Random Episode Selector, Keyboard MouseMover, CopyPath v2.1, SmartRename for XP,Window Tracer[sup]New![/sup]

Link to comment
Share on other sites

I haven't used it myself all that much, but I believe what you're looking for is GUISwitch()

#include <GUIConstants.au3>

$GUI1 = GUICreate("My GUI1", 200, 200, 100, 100)
$Button1 = GUICtrlCreateButton("Button 1", 50, 50)
GUISetState (@SW_SHOW)

$GUI2 = GUICreate("My GUI2", 200, 200, 320, 100)
$Button2 =GUICtrlCreateButton("Button 2", 50, 50)
GUISetState (@SW_SHOW)

While 1
    $msg = GUIGetMsg()
    If $msg = $Button1 then
        GUISwitch($GUI1)
        GUISetState (@SW_Hide, "My GUI1")
    EndIf
    
    If $msg = $Button2 then
        GUISwitch($GUI2)
        GUISetState (@SW_Hide, "My GUI2")
    EndIf
    
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
Wend
Thanx for the extremely fast reply... and yes, it solved my problem. *bow* Edited by faldo
Link to comment
Share on other sites

Or you can use GUISetState, but you need the window handle for it, not "My GUI1". So it should work with the following code:

#include <GUIConstants.au3>

GUI1 = GUICreate("My GUI1", 200, 200, 100, 100) <---- See the GUI1 = before GUICreate... Like in Monamo's example.
$Button1 = GUICtrlCreateButton("Button 1", 50, 50)
GUISetState (@SW_SHOW)

GUI2 = GUICreate("My GUI2", 200, 200, 320, 100) <---- Use it in the same way
$Button2 =GUICtrlCreateButton("Button 2", 50, 50)
GUISetState (@SW_SHOW)

While 1
    $msg = GUIGetMsg()
    If $msg = $Button1 then GUISetState (@SW_Hide, GUI1)   <---- Use the GUI1 variable, which now has the window handle
    If $msg = $Button2 then GUISetState (@SW_Hide, GUI2)   <---- returned by the GUICreate.
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
Wend
Link to comment
Share on other sites

Hmm... GUISwitch() needs WinHandle-parameter too. I used the same GUI1 = GUICreate as Monamo did, and Monamo uses GUISwitch(GUI1) on his example. It looks like GUISetState( @SW_HIDE, GUI2 ) changes the active window too, so it's a bit better to use. You should compare the two following examples:

GUISetState (@SW_Hide, GUI1)
GUISetState (@SW_Show, GUI2)
GUISetState (@SW_Hide, GUI3)
GUISetState (@SW_Show, GUI1)

And

GUISwitch($GUI1)
GUISetState (@SW_Hide, "My GUI1")
GUISwitch($GUI2)
GUISetState (@SW_Show, "My GUI2") <--- Actually that "My GUI2" does nothing, and you can just use it like this...
GUISwitch($GUI3)
GUISetState (@SW_Hide)
GUISwitch($GUI1)
GUISetState (@SW_Show)

As you can see, the first one is much shorter etc...

Link to comment
Share on other sites

Hmm... GUISwitch() needs WinHandle-parameter too. I used the same GUI1 = GUICreate as Monamo did, and Monamo uses GUISwitch(GUI1) on his example. It looks like GUISetState( @SW_HIDE, GUI2 ) changes the active window too, so it's a bit better to use. You should compare the two following examples:

GUISetState (@SW_Hide, GUI1)
GUISetState (@SW_Show, GUI2)
GUISetState (@SW_Hide, GUI3)
GUISetState (@SW_Show, GUI1)

And

GUISwitch($GUI1)
GUISetState (@SW_Hide, "My GUI1")
GUISwitch($GUI2)
GUISetState (@SW_Show, "My GUI2") <--- Actually that "My GUI2" does nothing, and you can just use it like this...
GUISwitch($GUI3)
GUISetState (@SW_Hide)
GUISwitch($GUI1)
GUISetState (@SW_Show)

As you can see, the first one is much shorter etc...

Yes indeed they both need a WinHandle, what i meant was that other functions that don't have a WinHandle parameter could use GUISwitch() to define what GUI to use as reference <_<
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...