Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate

How to check if a window is hidden?


  • Please log in to reply
12 replies to this topic
  • Guests
  • Last active:
  • Joined: --
I know the id of a window. What is the simplest way to check if the window is currently hidden (by Gui Hide) or visible?

closed
  • Members
  • 509 posts
  • Last active: Jan 14 2012 06:14 PM
  • Joined: 07 Feb 2008
from the helpfile on DllCall()

; Example: Calls the API function "IsWindowVisible" to find out if a Notepad window is visible.

DetectHiddenWindows On
if not DllCall("IsWindowVisible", "UInt", WinExist("Untitled - Notepad")) ; WinExist() returns an HWND.
MsgBox The window is not visible.



  • Guests
  • Last active:
  • Joined: --
Thanks. I thought there was a pure AHK solution like calling WinGet or WinGetPos with the hwnd and from some returned value I can tell the window is not currently visible.

It's kind of surprising it can only be done with dllcall.

xhacker
  • Guests
  • Last active:
  • Joined: --

Thanks. I thought there was a pure AHK solution like calling WinGet or WinGetPos with the hwnd and from some returned value I can tell the window is not currently visible.

It's kind of surprising it can only be done with dllcall.

Well you can do it with WinGetPos (or some other window commands), but it is a 2 step process. Assuming you have the hwnd (but you can use wintitle or winclass).

DetectHiddenWindows, off
WinGetPos, x,,,,ahk_id %hwnd%
if !x { 				; Window is hidden or does not exist
  DetectHiddenWindows, on
  WinGetPos, x,,,,ahk_id %hwnd%
  if x
    msgbox, Window exists and is hidden
}
Note, you might want to save A_DetectHiddenWindows so you can restore the DetectHiddenWindows state after you have done the detection.

Or you could just use the DllCall mentioned by yume. ;)

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005

It's kind of surprising it can only be done with dllcall.


It can be:

Gui, Show, w640 h480 [color=red]Hide[/color], My Window

WinGet, Style, Style, My Window 
If (Style & 0x10000000)  ; 0x10000000 is WS_VISIBLE
      MsgBox, My Window is Visible
Else  MsgBox, My Window is Hidden


  • Guests
  • Last active:
  • Joined: --
This winget, style method was what I was looking for. It's working perfectly.

Thanks everyone.

  • Guests
  • Last active:
  • Joined: --
Actually, I found none of that style bit checking is necessary, because if detecthiddenwindows is off then

WinGet, Style, Style, ahk_id %hwnd%

returns Style as empty, so it's enough to check that.

  • Guests
  • Last active:
  • Joined: --

returns Style as empty


when the window is hidden

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005

because if detecthiddenwindows is off then


..then you can use WinExist( "ahk_id" hwnd ) straight..
BTW, do not have such aversion to DllCall().. It can really improve your coding.

  • Guests
  • Last active:
  • Joined: --
I don't have an aversion, only I like simple solutions better.

Isn't

WinExist( "ahk_id" hwnd )

nicer and simpler than

DllCall("IsWindowVisible", "UInt", WinExist("Untitled - Notepad"))

?

I think so.

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005

I like simple solutions better.


Whatever suits you friend... But I need to here that it is bad coding practice to rely on a method that will be affected by A_DetectHiddenWindows

Edit: You need not reply.. My comment was for the future visitors of this topic.

  • Guests
  • Last active:
  • Joined: --

Whatever suits you friend... But I need to here that it is bad coding practice to rely on a method that will be affected by A_DetectHiddenWindows


I agree, but isn't the suggested DllCall method also relies on A_DetectHiddenWindows being on? At least in the 2nd post the poster explicitly turned it on, before invoking dllcall.

So it's not like that solution is independent of its value.

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005

but isn't the suggested DllCall method also relies on A_DetectHiddenWindows being on?


DetectWindows, On and A_DetectHiddenWindows are internal facilites of AutoHotkey.
Microsoft API functions will never see it.