Jump to content
Sign in to follow this  
funkey

WinSetState and GuiSetState

Recommended Posts

funkey

If I hide a Gui with GuiSetState and show it again with WinSetState, then I can't do anything with the Gui. All controls do not send messages.

When I have only one Skript this is no probelm, because I always use GuiSetState to hide and show the guis, but if I have more scripts I can not use GuiSetState to show the Gui from another script.

Should I always use WinSetState to hide Guis or is this a bug?

#include <GUIConstantsEx.au3>

GUICreate("Test bug with WinSetState", 210, 160)

GUICtrlCreateLabel("Please test all buttons!", 10, 10)
$YesID = GUICtrlCreateButton("Yes", 10, 50, 50, 20)
$NoID = GUICtrlCreateButton("No", 80, 50, 50, 20)
$BugID = GUICtrlCreateButton("Test Bug", 150, 50, 50, 20)
$ListViewID = GUICtrlCreateListView("Test1|Test2", 10, 80, 190, 70)


; Set accelerators for y and n
Dim $AccelKeys[2][2]=[["y", $YesID], ["n", $NoID]]
GUISetAccelerators($AccelKeys)

GUISetState()  ; display the GUI

Do
    $msg = GUIGetMsg()

    Select
        Case $msg = $YesID
            MsgBox(0, "You clicked on", "Yes")
        Case $msg = $NoID
            MsgBox(0, "You clicked on", "No")
  Case $msg = $ListViewID
            MsgBox(0, "You clicked on", "ListView")
  Case $msg = $BugID
;~    WinSetState('Test bug with WinSetState','',@SW_HIDE) ;hiding with WinSetState works
   GUISetState(@SW_HIDE)  ; hide the GUI ;hiding with GuiSetState doesn't works
   Sleep(1000)
   WinSetState('Test bug with WinSetState','',@SW_SHOW)
    EndSelect
Until $msg = $GUI_EVENT_CLOSE

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Share this post


Link to post
Share on other sites
zorphnog

You can use WinSetState to hide the window as well and everything is ok. I would suggest using that or incorporating all your GUIs/Scripts into one script.

I've never seen the source code, but I imagine that GuiSetState handles processing for gui messages of the controls internally. By hiding the window using GuiSetState, the processing of the messages is stopped for performance improvements. Showing the window using WinSetState does not re-enable the processing of those messages and therefore you see the problem you are getting. Using WinSetState exclusively, you will technically be slightly degrade performance, but I doubt that you will be able to notice it.

Share this post


Link to post
Share on other sites
funkey

Thanks a lot, zorphnog. I will now use WinSetState for all Guis I want to hide. I don't think performance will be a problem.


Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

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  

×