Jump to content

Detect a window z position


Recommended Posts

I was doing a simple script and testing it out (very impressed!)

however, when I ran the script as a demo to a client, the Au3Info window was still visible -- so when the script moved the mouse, it clicked on the info window rather than the window it should have clicked on....

No problem I thought; I'll just test to see what window is upper most... I can find a function that sets a window to always be on top... but I can't find one to set the Z position of a window, or read it..

How can I read the window list & each window's z position to determine if "my" window is on top or not?

Thanks

-josh

Link to comment
Share on other sites

I was doing a simple script and testing it out (very impressed!)

however, when I ran the script as a demo to a client, the Au3Info window was still visible -- so when the script moved the mouse, it clicked on the info window rather than the window it should have clicked on....

No problem I thought; I'll just test to see what window is upper most... I can find a function that sets a window to always be on top... but I can't find one to set the Z position of a window, or read it..

How can I read the window list & each window's z position to determine if "my" window is on top or not?

Thanks

-josh

Try This

; Check if a new notepad window is active
$state = WinGetState("Untitled", "")

; Is the window active?
If BitAnd($state, 8) Then
    MsgBox(0, "Example", "Window is Active")
Else
    MsgBox(0, "Example", "Window is Not Active")
EndIf
Edited by LimeSeed
global $warming = true
Link to comment
Share on other sites

Try This

; Check if a new notepad window is active
$state = WinGetState("Untitled", "")

; Is the window active?
If BitAnd($state, 8) Then
    MsgBox(0, "Example", "Window is Active")
Else
    MsgBox(0, "Example", "Window is Not Active")
EndIf

it can be "topmost" and "not active" -- I need to tell the z order of the window; not it's active state....

thanks

-josh

Link to comment
Share on other sites

it can be "topmost" and "not active" -- I need to tell the z order of the window; not it's active state....

thanks

-josh

You need the GetWindow function in User32.dll. There might be an example somewhere. (In fact, since ProgAndy is watching I feel an example coming soon.)
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

(In fact, since ProgAndy is watching I feel an example coming soon.)

Well, then I must answer ;)

To get the z-order, just use WinList. $arWinlist[1][1] is the handle to the window with highest z-order, , the last in Array the one with the lowest z-order

To get the topmost attribute, just use:

#include <Array.au3>
$list = WinList() 
; Array[ 1 ][ 1 ]           is window with highest z-order
; Array[ Array[0][0] ][ 1 ] is window with lowest z-order

;Add 3rd col with Bool Topmost attribute
ReDim $list[$list[0][0]+1][3]

$list[0][1] = "[Handle]" ; add description
$list[0][2] = "[TOPMOST window]" ; add description

For $i = 1 To $list[0][0]
    $list[$i][2] = _WinIsOnTop($list[$i][1])
Next

; Display 
_ArrayDisplay($list)

;===============================================================================
;
; 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
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

Well, then I must answer :D

To get the z-order, just use WinList. $arWinlist[1][1] is the handle to the window with highest z-order, , the last in Array the one with the lowest z-order

To get the topmost attribute, just use:

#include <Array.au3>
$list = WinList() 
; Array[ 1 ][ 1 ]           is window with highest z-order
; Array[ Array[0][0] ][ 1 ] is window with lowest z-order

;Add 3rd col with Bool Topmost attribute
ReDim $list[$list[0][0]+1][3]

$list[0][1] = "[Handle]" ; add description
$list[0][2] = "[TOPMOST window]" ; add description

For $i = 1 To $list[0][0]
    $list[$i][2] = _WinIsOnTop($list[$i][1])
Next

; Display 
_ArrayDisplay($list)

;===============================================================================
;
; 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
Thanks for maintaining my confidence ProgAndy! ;)
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Well, then I must answer ;)

Thank you ProgAndy!!! I will test out your example.

I didn't now the array order had anything to do with z order at all... so good info.

I was sort of suprised that there wasn't a "WinOnTOp()" that returned the top most window...

Thank you very much

-josh

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...