Jump to content

GUISetState versus WinSetState


Recommended Posts

I was wondering how exactly the functions GUISetState and WinSetState differ. More precisely, what does GUISetState() do other than just setting the main gui window state to @SW_SHOW? The following code illustrates that there is a difference:

#include <GUIConstants.au3>

Local $hGui = GUICreate("Hello", 70, 30, 100, 100)
Local $hBtn = GUICtrlCreateButton("Click me", 10, 5, 50)

;~ GUISetState(@SW_SHOW, $hGui)
WinSetState($hGui, "", @SW_SHOW)

Local $msg
Do
    $msg = GUIGetMsg()
    Select
        Case $msg = $hBtn
            MsgBox(0, "", "Clicked")            
    EndSelect
Until $msg = $GUI_EVENT_CLOSE

The button here doesn't function after using WinSetState, but it does using GUISetState. Any hints?

Link to comment
Share on other sites

  • Developers

The button here doesn't function after using WinSetState, but it does using GUISetState. Any hints?

mmmmm :) ... use GUISetState() ?

:)

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

GUISetState

Changes the state of a GUI window.... Thats the one you create with GUICreate()

********************************

WinSetState

Shows, hides, minimizes, maximizes, or restores a window. ... Thats for windows that are already created

AFAIK

8)

Edited by Valuater

NEWHeader1.png

Link to comment
Share on other sites

  • Developers

The window is created with GuiCreate(). My "wild guess" is that GuiSetState shows the Window and activates the MessagePump needed to read the Messages coming from the controls, but I haven't checked it. :)

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

That's a good question....

In the context you show, the documentation for GUISetState does say: "you MUST you this function....", however I would not have expected the result your example demonstrates.

Beyond the context of your example, I HAD the understanding that GUISetState can only be used on windows created with GUICreate, whereas WinSetState can be used with either (except, as you have shown).

HOWEVER, that does not seem to be the case. Using your example, if I show the window and hide it using GUISetState, and then show it with WinSetState,

the button still doesn't work.

Thanks for pointing this out.

Edit: The more I thought about it, I found your example to be "alarming". I just did a search on all my code and indeed found one place where I did a WinSetState instead of a GUISetState. It easy to do since there is no GUIGetState, just WinGetState. In general I find the AutoIt documentation to be very good. I think it could be clearer though with respect to this subject: when CAN'T you use a WIN function on a window created by GUICreate.

Personally, I would consider your example to demonstrate a bug; primarily because, as you have shown, WinGetState did indeed perform its function (i.e. the window became visible) but it had an undetectable (@error = 0) detrimental effect on the environment.

Edited by pdaughe
Link to comment
Share on other sites

The window is created with GuiCreate(). My "wild guess" is that GuiSetState shows the Window and activates the MessagePump needed to read the Messages coming from the controls, but I haven't checked it. :)

Jos

That's what I thought too and is why I did a GUISetState @SW_SHOW Then GUISetState @SW_HIDE, followed by the WinSetState. The WinSetState has an unpredictable effect. This post initially caught my attention because I was having similar types of "unexplainable" problems a few months ago and then they (mysteriously) disappeared. Now I think it was because I changed the WinSetState to a GUISetState in a SHOW_WINDOW UDF I use all over the place...
Link to comment
Share on other sites

mmmmm :) ... use GUISetState() ?

:)

I stumbled across the issue trying to figure out how to use controls in a hidden gui. I more wanted to know if there was a way to do the extra stuff GUISetState() does without showing the window. It seems easy enough to work around, just thought maybe I could learn something new. As far as I can tell GUISetState @SW_SHOW followed by WinSetState @SW_HIDE does the trick.

Anyway thanks for the quick replies.

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