Jump to content

Recommended Posts

Posted

Hello,

I'm trying to detect if no window is active, when a hotkey is pressed.

I tried to see if I can use the ClassName:

#include <WinAPISysWin.au3>
While 1
    ConsoleWrite(_WinAPI_GetClassName(WinGetHandle("[ACTIVE]"))&@LF)
    Sleep(500)
WEnd

But desktop, Taskbar, SystemTray and Start has their own ClassNames and this way I have to have a black/white list and these ClassNames are probably different in Windows 10 and 7.

Is there a better way to detect if no window is active?

Thanks.

Posted (edited)

If you want to see if a handle is a "real window", you can use this:

Func _isReal($hWnd)
    $vWinStyle = _WinAPI_GetWindowLong($hWnd, $GWL_STYLE)
    If BitAND(WinGetState($hWnd), 4) = 4 _
        And BitAND($vWinStyle, $WS_VISIBLE) = $WS_VISIBLE _
        And BitAND($vWinStyle, $WS_MINIMIZE) <> $WS_MINIMIZE _
        And BitAND($vWinStyle, $WS_MINIMIZEBOX) = $WS_MINIMIZEBOX _
        And BitAND($vWinStyle, $WS_MAXIMIZEBOX) = $WS_MAXIMIZEBOX Then Return True
EndFunc

And you can use it like this

$hWnd = WinGetHandle("[ACTIVE]")
If _isReal($hWnd) Then
    ;do something...
EndIf

Solved.

 

Edited by leomoon
Posted
6 hours ago, leomoon said:

you can use it like this

Try this 😉

#include <WinAPISysWin.au3>
#include <WindowsConstants.au3>

GUICreate("Test: active window ")
GUISetState()
Sleep(1111)

$hWnd = WinGetHandle("[ACTIVE]")
ConsoleWrite(WinGetTitle($hWnd))
If _isReal($hWnd) Then
    ConsoleWrite("is real" & @CRLF)
Else
    ConsoleWrite("is NOT real" & @CRLF)
EndIf

Func _isReal($hWnd)
    $vWinStyle = _WinAPI_GetWindowLong($hWnd, $GWL_STYLE)
    If BitAND(WinGetState($hWnd), 4) = 4 _
        And BitAND($vWinStyle, $WS_VISIBLE) = $WS_VISIBLE _
        And BitAND($vWinStyle, $WS_MINIMIZE) <> $WS_MINIMIZE _
        And BitAND($vWinStyle, $WS_MINIMIZEBOX) = $WS_MINIMIZEBOX _
        And BitAND($vWinStyle, $WS_MAXIMIZEBOX) = $WS_MAXIMIZEBOX Then Return True
EndFunc

 

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
  • Recently Browsing   0 members

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