Jump to content

WinSetState and GuiSetState


Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 10 years later...

Apples and oranges, but you can mix them.  The trick is you hide the control, make your change and then show the control.  

I had that same problem and then I switched to GUISetState instead of WinSetstate and no longer had to do that.

11 years late, sorry, but for the next person looking for 'How to change a GUI control without hiding it first.'  

 

Link to comment
Share on other sites

  • Moderators

@InternetMonkeyBoy  as you yourself acknowledge, this post is over 10 years old. Please don't resurrect old threads; especially when the OP states he found a resolution.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...