Jump to content

How does to know a window is Topmost?


Recommended Posts

To test for the $WS_EX_TOPMOST property, use something like this:

$hWin = WinGetHandle("Untitled - Notepad")
$avStyles = GUIGetStyle($hWin) ; [0] = Style, [1] = ExStyle
$fTopMost = BitAND($avStyles[1], $WS_EX_TOPMOST)
If $fTopMost Then
    ConsoleWrite("Debug: Window with handle $hWin has $WS_EX_TOPMOST set.")
Else
    ConsoleWrite("Debug: Window with handle $hWin does not have $WS_EX_TOPMOST set.")
EndIf

:P

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

  • 5 months later...

Sorry for bringing an old thread back to life, but I also need this question answered.

The script posted by PsaltyDS doesn't work as I'm not using an AutoIT GUI, but rather a third party program created window.

Any idea how to read the topmost field of a non AutoIT window?

Link to comment
Share on other sites

Sorry for bringing an old thread back to life, but I also need this question answered.

The script posted by PsaltyDS doesn't work as I'm not using an AutoIT GUI, but rather a third party program created window.

Any idea how to read the topmost field of a non AutoIT window?

So? You enter the title of your 3rd party window.

Const $WS_EX_TOPMOST = 0x8
$hWin = WinGetHandle("Untitled - Notepad")
$avStyles = GUIGetStyle($hWin) ; [0] = Style, [1] = ExStyle
$fTopMost = BitAND($avStyles[1], $WS_EX_TOPMOST)
If $fTopMost Then
    ConsoleWrite("Debug: Window with handle $hWin has $WS_EX_TOPMOST set.")
Else
    ConsoleWrite("Debug: Window with handle $hWin does not have $WS_EX_TOPMOST set.")
EndIf
Edited by weaponx
Link to comment
Share on other sites

No, this doesn't work. GUIGetStyle only works with Au3-Windows. Use this instead :)

$hWin = WinGetHandle("Untitled")
$fTopMost = _WinIsOnTop($hWin)
If $fTopMost Then
    ConsoleWrite("Debug: Window with handle $hWin has $WS_EX_TOPMOST set.")
Else
    ConsoleWrite("Debug: Window with handle $hWin does not have $WS_EX_TOPMOST set.")
EndIf

;===============================================================================
;
; Function Name:   _WinIsOnTop
; Description::    Gets the OnTop State of a window
; Parameter(s):    $WindowHandle : Handle or Title of Window
; Requirement(s):  WinAPI.au3
; Return Value(s): Window OnTop: True, otherwise False
; Author(s):       Prog@ndy
;
;===============================================================================
;
Func _WinIsOnTop($WindowHandle)
    Local $long = DllCall("User32.dll", "int", "GetWindowLong", "hwnd", WinGetHandle($WindowHandle), "int", -20)
    Return BitAND($long[0],8)=8 ; $WS_EX_TOPMOST = 8
EndFunc

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

No, this doesn't work. GUIGetStyle only works with Au3-Windows. Use this instead :)

$hWin = WinGetHandle("Untitled")
$fTopMost = _WinIsOnTop($hWin)
If $fTopMost Then
    ConsoleWrite("Debug: Window with handle $hWin has $WS_EX_TOPMOST set.")
Else
    ConsoleWrite("Debug: Window with handle $hWin does not have $WS_EX_TOPMOST set.")
EndIf

;===============================================================================
;
; Function Name:   _WinIsOnTop
; Description::    Gets the OnTop State of a window
; Parameter(s):    $WindowHandle : Handle or Title of Window
; Requirement(s):  WinAPI.au3
; Return Value(s): Window OnTop: True, otherwise False
; Author(s):       Prog@ndy
;
;===============================================================================
;
Func _WinIsOnTop($WindowHandle)
    Local $long = DllCall("User32.dll", "int", "GetWindowLong", "hwnd", WinGetHandle($WindowHandle), "int", -20)
    Return BitAND($long[0],8)=8 ; $WS_EX_TOPMOST = 8
EndFunc
You've got the right idea, but this is already included in AutoIt as _WinAPI_GetWindowLong().

:(

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

I know, but this way it's easier to use and you don't have to include the whole UDF just for 1 line of code :)

The only line from WInAPI.au3 is the DLLcall.... WINAPI.au3 has 4698 lines :(

Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

I know, but this way it's easier to use and you don't have to include the whole UDF just for 1 line of code :)

The only line from WInAPI.au3 is the DLLcall.... WINAPI.au3 has 4698 lines :(

This is true.

Looking at your code, is there a reason why you use wingethandle() in the dllcall line when you already have the handle of the window passed-in?

Thanks to both yourself and PsaltyDS for the fast reply.

Link to comment
Share on other sites

Looking at your code, is there a reason why you use wingethandle() in the dllcall line when you already have the handle of the window passed-in?

It's to use it easier. You can pass a WindowTitle, too, When you do it this way :=)

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
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
 Share

  • Recently Browsing   0 members

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