amin84 Posted September 8, 2019 Posted September 8, 2019 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.
amin84 Posted September 9, 2019 Author Posted September 9, 2019 (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 September 9, 2019 by leomoon
InnI Posted September 9, 2019 Posted September 9, 2019 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now