Jump to content



Photo

[Solved] Is There a WinGetOnTop() Function?


  • Please log in to reply
5 replies to this topic

#1 Zohar

Zohar

  • Active Members
  • PipPipPipPipPipPip
  • 511 posts

Posted 06 March 2012 - 07:02 PM

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, 06 March 2012 - 07:19 PM.








#2 KaFu

KaFu

    Hey, it's just me, KhaFoo...

  • MVPs
  • 3,166 posts

Posted 06 March 2012 - 07:08 PM

#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:

AutoIt         
#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, 06 March 2012 - 07:13 PM.


#3 KaFu

KaFu

    Hey, it's just me, KhaFoo...

  • MVPs
  • 3,166 posts

Posted 06 March 2012 - 07:13 PM

: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, 06 March 2012 - 07:16 PM.


#4 Zohar

Zohar

  • Active Members
  • PipPipPipPipPipPip
  • 511 posts

Posted 06 March 2012 - 07:18 PM

hehe :oops:

Sorry I deleted it by mistake.

And regarding your function,
it works amazing!!

Thank you very much for it (:

#5 UEZ

UEZ

    Never say never

  • MVPs
  • 3,617 posts

Posted 06 March 2012 - 08:02 PM

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, 06 March 2012 - 08:12 PM.

 
The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯


#6 Zohar

Zohar

  • Active Members
  • PipPipPipPipPipPip
  • 511 posts

Posted 07 March 2012 - 03:35 PM

Very nice
Thank you UEZ




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users