Jump to content
Sign in to follow this  
Zohar

[Solved] Is There a WinGetOnTop() Function?

Recommended Posts

Zohar

Hi

To change a window's AlwaysOnTop property, we can use the WinSetOnTop() function.

But If I need to Check a window's AlwaysOnTop property, I did not find a WinGetOnTop() function.

How can I write such one?

Or if anyone wrote on and can post it, it can help.

Thank you

Edited by Zohar

Share this post


Link to post
Share on other sites
KaFu

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <Constants.au3>

$hGUI = GUICreate("My GUI")
GUISetState(@SW_SHOW)

ConsoleWrite(BitAND(_WinAPI_GetWindowLong($hGUI, $GWL_EXSTYLE), $WS_EX_TOPMOST) & @CRLF)
WinSetOnTop($hGUI, "", 1)
ConsoleWrite(BitAND(_WinAPI_GetWindowLong($hGUI, $GWL_EXSTYLE), $WS_EX_TOPMOST) & @CRLF)
WinSetOnTop($hGUI, "", 0)
ConsoleWrite(BitAND(_WinAPI_GetWindowLong($hGUI, $GWL_EXSTYLE), $WS_EX_TOPMOST) & @CRLF)

While 1
    $msg = GUIGetMsg()

    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd
GUIDelete()

Edit:

Or as a separate function:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <Constants.au3>

$hGUI = GUICreate("My GUI")
GUISetState(@SW_SHOW)

ConsoleWrite(_WinGetOnTop($hGUI) & @CRLF)
WinSetOnTop($hGUI, "", 1)
ConsoleWrite(_WinGetOnTop($hGUI) & @CRLF)
WinSetOnTop($hGUI, "", 0)
ConsoleWrite(_WinGetOnTop($hGUI) & @CRLF)

While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd
GUIDelete()

Func _WinGetOnTop($hWnd)
    If BitAND(_WinAPI_GetWindowLong($hWnd, $GWL_EXSTYLE), $WS_EX_TOPMOST) Then Return 1
    Return 0
EndFunc   ;==>_WinGetOnTop
Edited by KaFu

Share this post


Link to post
Share on other sites
KaFu

:oops: afaik it should work fine...

Edit:

For the record, I'm not talking to myself (yet) :bye:... the post before this (asking if this works for none Autoit windows too) was deleted by the OP...

Edited by KaFu

Share this post


Link to post
Share on other sites
Zohar

hehe :oops:

Sorry I deleted it by mistake.

And regarding your function,

it works amazing!!

Thank you very much for it (:

Share this post


Link to post
Share on other sites
UEZ

Here my version:

#include <constants.au3>
#include <windowsconstants.au3>
#include <winapi.au3>

HotKeySet("{ESC}", "_Exit")

Do
    $aRet = DllCall("user32.dll", "int", "WindowFromPoint", "long", MouseGetPos(0), "long", MouseGetPos(1))
    $state = _WinAPI_GetWinTopmostState(HWnd($aRet[0]))
    ToolTip(_WinAPI_GetWindowText(_WinAPI_GetAncestor(HWnd($aRet[0]), $GA_ROOT)) & " = " & $state, MouseGetPos(0) + 30, MouseGetPos(1) + 20, "Is on top", 1, 4)
Until Not Sleep(50)

Func _Exit()
    Exit
EndFunc

Func _WinAPI_GetWinTopmostState($hWnd)
    Local $hWnd_Root = _WinAPI_GetAncestor($hWnd, $GA_ROOT)
    Return BitAND(_WinAPI_GetWindowLong($hWnd_Root, $GWL_EXSTYLE), $WS_EX_TOPMOST) = True
EndFunc

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

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
Sign in to follow this  

×