Sign in to follow this  
Followers 0
Info

GUISwitch

16 posts in this topic

Case $msg = $BlaBlaButton
GuiSwitch ($GuiNumber2)
bla bla bla

It just opens the two GUI's at the same time when I run it.

I want it to open the "$GuiNumber2" when I click the "$BlaBlaButton".

Help please.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Here is a simple example of one way to do what I interpreted you wanted to do:

#include <GuiConstants.au3>

Opt('GuiOnEventMode',1)

$Gui_1= GUICreate("Window 1", 200, 100, 200)
$Button_1 = GUICtrlCreateButton("Switch", 60, 30, 80, 40)
GUICtrlSetOnEvent(-1, "GUI_Switch")
GUISetState()

$Gui_2= GUICreate("Window 2", 200, 100, 800)
$Button_2 = GUICtrlCreateButton("Switch", 60, 30, 80, 40)
GUICtrlSetOnEvent(-1, "GUI_Switch")
GUISetState(@SW_HIDE)

While 1
    Sleep(100)
WEnd

Func GUI_Switch()
    If IsVisible($Gui_1) Then
        GUISetState(@SW_SHOW,$Gui_2)
        GUISetState(@SW_HIDE,$Gui_1)
    ElseIf IsVisible($Gui_2) Then
        GUISetState(@SW_SHOW,$Gui_1)
        GUISetState(@SW_HIDE,$Gui_2)
    EndIf
EndFunc

Func IsVisible($handle)
    If BitAnd( WinGetState($handle), 2 ) Then 
        Return 1
    Else
        Return 0
    EndIf
EndFunc
Edited by Paulie

Share this post


Link to post
Share on other sites

I understand nothing in there, can you explain a little bit?

And what's wrong with the script I posted?

Share this post


Link to post
Share on other sites

UPPP.

Help me please.

Share this post


Link to post
Share on other sites

And what's wrong with the script I posted?

Well, for one, it isn't actually a script; it's Pseudo-code.

For two, GuiSwitch doesn't actually switch windows. To quote the helpfile:

Many of the GUI specific functions work on the "current" window - this is usually the last window created with GUICreate. This function allows you to make another window "current". That's does not mean that the referenced window will become active. You have to use WinActivate.

I understand nothing in there, can you explain a little bit?

Commented code:

#include <GuiConstants.au3>

Opt('GuiOnEventMode',1);Turn on GUIOneventMode

$Gui_1= GUICreate("Window 1", 200, 100, 200);Create the first GUI window
$Button_1 = GUICtrlCreateButton("Switch", 60, 30, 80, 40);Create the button in the first GUI window
GUICtrlSetOnEvent(-1, "GUI_Switch"); set the button to call the Gui_Switch() Function when clicked
GUISetState();display the GUI

$Gui_2= GUICreate("Window 2", 200, 100, 800);Create the second GUI window
$Button_2 = GUICtrlCreateButton("Switch", 60, 30, 80, 40); create the button in the second GUI window
GUICtrlSetOnEvent(-1, "GUI_Switch"); set the button to call the Gui_Switch() Function when clicked
GUISetState(@SW_HIDE); Set the state of the window to be hidden

While 1 ;A simple loop to keep the script alive while it waits for an event
    Sleep(100)
WEnd

Func GUI_Switch();switches the 2 GUIs between the states "Hidden" and "Visible"
    If IsVisible($Gui_1) Then ; If the first GUI is visible then
        GUISetState(@SW_SHOW,$Gui_2) ; make the second GUI visible
        GUISetState(@SW_HIDE,$Gui_1) ; Hide the first GUI
    ElseIf IsVisible($Gui_2) Then ;otherwise, if the second window is visible then
        GUISetState(@SW_SHOW,$Gui_1) ; make the first one visible
        GUISetState(@SW_HIDE,$Gui_2) ; hide the second one
    EndIf
EndFunc

Func IsVisible($handle); determines if a window is visible (taken from the helpfile)
    If BitAnd( WinGetState($handle), 2 ) Then
        Return 1
    Else
        Return 0
    EndIf
EndFunc

Share this post


Link to post
Share on other sites

I don't really want the windows to get switched... :)

I just want that after I click on a button in the main GUI, another GUI will get opend and will be infront of GuiNumber1.

And if I click on the X in GuiNumber2, it will exit only GuiNumber2, and leave GuiNumber1...

THANKS...

Share this post


Link to post
Share on other sites

I don't really want the windows to get switched... :)

I just want that after I click on a button in the main GUI, another GUI will get opend and will be infront of GuiNumber1.

And if I click on the X in GuiNumber2, it will exit only GuiNumber2, and leave GuiNumber1...

THANKS...

This?:

#include <GUIConstants.au3>

$MainGui = GuiCreate("Main GUI", 200, 100)

$SwitchBtn1 = GUICtrlCreateButton("Switch to child", 55, 40, 90, 25)

$ChildGui = GUICreate("Child GUI", 160, 80, -1, -1, -1, -1, $MainGui)

$SwitchBtn2 = GUICtrlCreateButton("Switch to Main", 35, 40, 90, 25)

GUISetState(@SW_SHOW, $MainGui)

While 1
    $msg = GUIGetMsg(1)
    Select
    Case $msg[0] = $GUI_EVENT_CLOSE And $msg[1] = $MainGui
        Exit
    Case ($msg[0] = $GUI_EVENT_CLOSE And $msg[1] = $ChildGui) Or ($msg[0] = $SwitchBtn2)
        GUISetState(@SW_ENABLE, $MainGui)
        GUISetState(@SW_HIDE, $ChildGui)
    Case $msg[0] = $SwitchBtn1
        GUISetState(@SW_DISABLE, $MainGui)
        GUISetState(@SW_SHOW, $ChildGui)
    EndSelect
WEnd

Share this post


Link to post
Share on other sites

I, too, was interestd in 'nested' gui's or parent child. I took another example that was posted and shorted it up considerably. Perhaps this will help others as well.

CODE
#include <GUIConstants.au3>

$Screen1 = GUICreate("Screen 1", 332, 157, 436, 190)

$MenuFile = GUICtrlCreateMenu("&File")

$MenuItemExit = GUICtrlCreateMenuItem("Exit", $MenuFile)

$MenuScreen1 = GUICtrlCreateMenu("&Screen 2")

$MenuGetScreen2 = GUICtrlCreateMenuItem("Goto Screen 2", $MenuScreen1)

GUISetState(@SW_SHOW)

$Screen2 = GUICreate("Screen 2", 370, 397, 433, 158, -1, -1, $Screen1)

GUICtrlCreateGroup("", -99, -99, 1, 1)

$InputGroup = GUICtrlCreateInput("", 56, 16, 193, 21)

$LabelName = GUICtrlCreateLabel("Name:", 16, 17, 35, 17)

GUICtrlCreateGroup("", -99, -99, 1, 1)

GUISetState(@SW_HIDE)

While 1

$Msg = GUIGetMsg(1)

$CTRLMsg = $Msg[0]

$Win = $Msg[1]

Select

Case $CtrlMsg = $GUI_EVENT_CLOSE AND $Win = $Screen1

GUIDelete()

Exit

Case $CtrlMsg = $GUI_EVENT_CLOSE AND $Win = $Screen2

WinSetState("Screen 2","",@SW_HIDE)

Case $CtrlMsg = $MenuItemExit

Exit

Case $CtrlMsg = $MenuGetScreen2

WinSetState("Screen 2","",@SW_SHOW)

WinActivate("Screen 2")

EndSelect

WEnd

Exit

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

@ericg32

The code you posted doesn't allow for Screen 2 to send GUI actions. I think you have to use rasim's idea and disable the first window so that the windows handler knows which window to listen to. I think AutoIt only supports single threading on window controls. If you want two independent windows then you may have to use two scripts and make them pass variables to each other. Someone please correct me if I'm wrong.

#include <GUIConstants.au3>

$Screen1 = GUICreate("Screen 1", 332, 157, 436, 190)
$MenuFile = GUICtrlCreateMenu("&File")
$MenuItemExit = GUICtrlCreateMenuItem("Exit", $MenuFile)
$MenuScreen1 = GUICtrlCreateMenu("&Screen 2")
$MenuGetScreen2 = GUICtrlCreateMenuItem("Goto Screen 2", $MenuScreen1)

GUISetState(@SW_SHOW)

$Screen2 = GUICreate("Screen 2", 370, 397, 433, 158, -1, -1, $Screen1)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$button = GUICtrlCreateButton("button",0,0)
$InputGroup = GUICtrlCreateInput("", 56, 16, 193, 21)
$LabelName = GUICtrlCreateLabel("Name:", 16, 17, 35, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_HIDE)

While 1
$Msg = GUIGetMsg(1)
$CTRLMsg = $Msg[0]
$Win = $Msg[1]

    Select
        Case $CtrlMsg = $GUI_EVENT_CLOSE AND $Win = $Screen1
            GUIDelete()
            Exit

        Case $CtrlMsg = $GUI_EVENT_CLOSE AND $Win = $Screen2
            WinSetState("Screen 2","",@SW_HIDE)

        Case $CTRLMsg = $button
            MsgBox(0,"button hit","button hit")

        Case $CtrlMsg = $MenuItemExit
            Exit

        Case $CtrlMsg = $MenuGetScreen2
            WinSetState("Screen 2","",@SW_SHOW)
            WinActivate("Screen 2")
    EndSelect
WEnd

Exit
Edited by ending

Share this post


Link to post
Share on other sites

I've tested all your scripts and the best one I found for me was Rasim's script.

The only problem I got is that: (Starting for $MenuGui)

Case $msg = $Button3
GUISetState(@SW_SHOW, $GuiNum2)
Case $msg = $GUI_EVENT_CLOSE
GUISetState(@SW_SHOW, $GuiNum1)
GUISetState(@SW_HIDE, $GuiNum2)

I just want that if I click on the red [X] in the GUI, the $ChildGui will exit and the $MenuGui will be there.

THANK YOU ALL :)

Share this post


Link to post
Share on other sites

I've tested all your scripts and the best one I found for me was Rasim's script.

The only problem I got is that: (Starting for $MenuGui)

Case $msg = $Button3
GUISetState(@SW_SHOW, $GuiNum2)
Case $msg = $GUI_EVENT_CLOSE
GUISetState(@SW_SHOW, $GuiNum1)
GUISetState(@SW_HIDE, $GuiNum2)

I just want that if I click on the red [X] in the GUI, the $ChildGui will exit and the $MenuGui will be there.

THANK YOU ALL :)

GUIDelete ()

Share this post


Link to post
Share on other sites

Can you put it in the code I posted?

Share this post


Link to post
Share on other sites

Ha ha whoa...Threw me off there Bert. Sorry, but that was kind of funny.

Share this post


Link to post
Share on other sites

F**k off no. I will not write it for you.

You suck O_o

Share this post


Link to post
Share on other sites

You suck, cause you can't work out where to put a GUIDelete. Think about. If you exit 1 GUI, where you still want the other to be there, what do you have to replace? The exit! Wow! Claps all around!

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