Belini

Difference between GuiSetState () and _WinAPI_ShowWindow ()

15 posts in this topic

#1 ·  Posted

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?

Share this post


Link to post
Share on other sites



#2 ·  Posted

I would also love to know the difference.

I have always used GuiSetState () but I started using _WinAPI_ShowWindow () and I would also like to know if there are any differences between the functions. ??????

 

:ILA2:

Share this post


Link to post
Share on other sites

#3 ·  Posted

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

 

Saludos

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

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

MENSAG_01: W_05_07_17

Edited by Belini

Share this post


Link to post
Share on other sites

#5 ·  Posted

@Danyfire

So is it better to use _WinAPI_ShowWindow ?
Or
GuiSetState () 
Or
Whatever ?

Thank you  :thumbsup:

Share this post


Link to post
Share on other sites

#6 ·  Posted

Belini Basically yes.

 

Fabio. keep using GUISetState.

 

Saludos

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

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

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#8 ·  Posted

Share this post


Link to post
Share on other sites

#9 ·  Posted

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.

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

@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

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

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

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

#13 ·  Posted

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   


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#14 ·  Posted

@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!

Share this post


Link to post
Share on other sites

#15 ·  Posted

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

 

Saludos

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