Sign in to follow this  
Followers 0
Kohr

help me understand GUISwitch

4 posts in this topic

I am trying to understand how to use GUISwitch and GUISetState. I basically wanted to eventually turn my existing coding projects into more of a GUIMain that has buttons that will have "popup" type windows that show up on top of the GUIMain window.

I believe I have the general concept of how to do this but I don't understand why the following code will not make the main window ($mainwindow) the active window once the popup ($dummywindow) is closed. Everything works fine except you have to click the $mainwindow to make it active and I would have guessed that my current code (GUISetState(@SW_ENABLE)) would do that. What am I missing here?

Thanks.

Kohr

#include <GUIConstants.au3>

Opt("GUIOnEventMode", 1) ; Change to OnEvent mode 
$mainwindow = GUICreate("main window", 400, 200)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")
GUICtrlCreateLabel("This will be the main window", 30, 10)
$okbutton = GUICtrlCreateButton("OK", 70, 50, 60)
GUICtrlSetOnEvent($okbutton, "OKButton")

$dummywindow = GUICreate("popup window", 200, 100)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")
$buttonDummy = GUICtrlCreateButton("MsgBox", 70, 50, 60)
GUICtrlSetOnEvent($buttonDummy , "buttonDummy")


GUISwitch($mainwindow)
GUISetState()

While 1
  Sleep(1000) ; Idle around
WEnd

Func OKButton()
  GUISetState(@SW_DISABLE)
  GUISwitch($dummywindow)
  GUISetState()
EndFunc

Func CLOSEClicked()
    ConsoleWrite("func close" & @CRLF)
    If @GUI_WINHANDLE = $mainwindow Then 
        Exit
    EndIf 
    If @GUI_WINHANDLE = $dummywindow Then 
        GUISetState(@SW_HIDE)
        GUISwitch($mainwindow)
        GUISetState(@SW_ENABLE)
    EndIf 
EndFunc

Func buttonDummy()
    MsgBox(0,"title","message")
EndFunc

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Try using this command instead:

(from the help file)

WinActivate

----------------------

Activates (gives focus to) a window.

WinActivate ( "title" [, "text"] )

I believe that GUISwitch only controls which window a new control will be created on. (in case you want to go back and add a control to a window you created before the window you're currently adding controls to).

GUISetState allows you to disable or enable, hide or show, etc your window, but enabling or showing a window won't activate it, it only enables it. You want to activate it, so use WinActivate (linked to in the "related" section of the WinSetState function's page in the help file).

Hope that helps!

Edited by james3mg

"There are 10 types of people in this world - those who can read binary, and those who can't.""We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true." ~Robert Wilensky0101101 1001010 1100001 1101101 1100101 1110011 0110011 1001101 10001110000101 0000111 0001000 0001110 0001101 0010010 1010110 0100001 1101110

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Well said! :)

What also might help you, Kohr, is that you can use the return value from GUICreate ($mainwindow in your case) as "title" parameter in WinActivate.

Edited by Manadar

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