Jump to content

Difference between GuiSetState () and _WinAPI_ShowWindow ()


 Share

Recommended Posts

I know that _WinAPI_ShowWindow () uses windows APIs to display windows and does exactly the same as GuiSetState () does and I did not find the source of GuiSetState () to compare, can anyone explain me what is the difference between the two functions?

Link to comment
Share on other sites

Hello. It is a wrapper of  _WinAPI_ShowWindow. Of course  GuiSetState do other things internally. But Yes it use ShowWindow API call.

 

Saludos

Link to comment
Share on other sites

@Danyfirex so their functions are the same, just change the name, right!

MENSAG_01: W_05_07_17

Edited by Belini
Link to comment
Share on other sites

Link to comment
Share on other sites

  • Developers

There is indeed no real difference other than GuiShow() will default to the last Handle of an internal created GUI and use @SW_SHOW as default.

Simple demonstration:

#include <GUIConstantsEx.au3>
#include <winapi.au3>

Example()

Func Example()
    $hwd=GUICreate("My GUI") ; start the definition
    GUISetState() ; will display an empty dialog box
    sleep(2000)
    _WinAPI_ShowWindow($hwd,@SW_HIDE )
    sleep(2000)
    _WinAPI_ShowWindow($hwd,@SW_SHOW )
    ; Loop until the user exits.
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
        EndSwitch
    WEnd
EndFunc   ;==>Example

The whole WinAPI stuff was only added at a later date and GuiShow() was obviously part of the GUI development JPM did.
You will find several overlaps between Internal Functions and UDF's .. but also between UDF's for that matter, like a list of Date functions.

Jos

Edited by 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

Link to comment
Share on other sites

Run this script. Click button two-three times to hide/show window

$gui = GUICreate("wnd", 200, 200)
$btn = GUICtrlCreateButton("click me", 50, 50, 100, 30)
GUISetState()

Do
  Switch GUIGetMsg()
    Case -3
      Exit
    Case $btn
      GUISetState(@SW_HIDE)
      GUICtrlSetData($btn, "click again")
      Sleep(500)
      GUISetState(@SW_SHOW)
  EndSwitch
Until 0

Now change string GUISetState(@SW_SHOW) to _WinAPI_ShowWindow($gui, @SW_SHOW)

; GUISetState(@SW_SHOW)
_WinAPI_ShowWindow($gui, @SW_SHOW)

And try again ;) (button does not work after showing the window)

It looks like function GUISetState does a little more than just displays the window.

Link to comment
Share on other sites

@InnI actually happens what you said and only hid when I used _WinAPI_ShowWindow ($ gui, @SW_HIDE) so when using _WinAPI_ShowWindow () to show you have to use _WinAPI_ShowWindow () to hide and this makes me think that the functions are not the same as I thought? Does anyone have the function code GuisetSte () to make the comparison?

#include <WinAPI.au3>

$gui = GUICreate("wnd", 200, 200)
$btn = GUICtrlCreateButton("click me", 50, 50, 100, 30)
GUISetState()

Do
  Switch GUIGetMsg()
    Case -3
      Exit
    Case $btn
     ; GUISetState(@SW_HIDE)
      _WinAPI_ShowWindow($gui, @SW_HIDE)
      GUICtrlSetData($btn, "click again")
      Sleep(500)
      ;GUISetState(@SW_SHOW)
      _WinAPI_ShowWindow($gui, @SW_SHOW)
  EndSwitch
Until 0

Jos: Please stick to English so we all understand the discussion:

Quote

@InnI really happens what you said and only hid when I used _WinAPI_ShowWindow ($ gui, @SW_HIDE) so when using _WinAPI_ShowWindow () to show, you should use _WinAPI_ShowWindow () to hide and this makes me think that functions do not Are they the same as I thought? Does anyone have the GuisetSte () function code to do the comparison?

 

Edited by Jos
Link to comment
Share on other sites

  • Developers

It is actually really doing the same thing, but the issue you have encountered here is that AutoIt3 has some extra logic not to process some message while hidden:

	// If the GUI is hidden then we don't want to trigger any messages because we may be modifying things
	// via the script when hidden

When you use _WinAPI_ShowWindow() for both hiding and showing the window, things will work fine and you won't have this extra logic applied.

Jos

Edited by 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

Exactly the same I believe that they are not therefore connsigo hide the taskbar using _WinAPI_ShowWindow () and if I use GUISetState () does not work!

#include <WinAPI.au3>

$hWnd = WinGetHandle("[CLASS:Shell_TrayWnd]")

_WinAPI_ShowWindow($hWnd, @SW_HIDE); hiding the taskbar
GUISetState(@SW_HIDE, $hWnd); So it does not hide the taskbar

 

Edited by Belini
Link to comment
Share on other sites

  • Developers

My "the same" was in relation to internal created GUI's with the GuiCreate() function with the  difference as written in my previous post.
I would not use GuiSetState() for any other windows.

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

@Jos you should know the GuiSetState () code and sure enough is right but I'm curious to see the GuiSetState () code to see the extra script that it has in!

Link to comment
Share on other sites

That's my suggestion too.  Use  GUISetState just for own script windows.

 

Saludos

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