Jump to content

Need Handles for Windows in Taskbar


Guest Robert Perry

Recommended Posts

Guest Robert Perry

I need a way to filter the list of window handles returned by the function WinList(). Specifically, I want *only* the handles of windows that have taskbar buttons, and I need to obtain this information without performing any actions on the windows themselves (e.g. minimize, hide, etc.). Is this possible with AutoIt?

Link to post
Share on other sites

I need a way to filter the list of window handles returned by the function WinList(). Specifically, I want *only* the handles of windows that have taskbar buttons, and I need to obtain this information without performing any actions on the windows themselves (e.g. minimize, hide, etc.). Is this possible with AutoIt?

The only thing I see in that area to cue on is the x/y location (not very helpful), and the "Pixel Color Under Mouse", which could be very useful if you had a limited number of apps to identify... ;)
...by the way, it's pronounced: "JIF"... Bob Berry --- inventor of the GIF format
Link to post
Share on other sites
Guest Robert Perry

I need a way to filter the list of window handles returned by the function WinList(). Specifically, I want *only* the handles of windows that have taskbar buttons, and I need to obtain this information without performing any actions on the windows themselves (e.g. minimize, hide, etc.). Is this possible with AutoIt?

This script does the trick (see code below):

taskbar.au3

I used this page as a resource:

http://www.thescarms.com/Vbasic/alttab.asp

; ---------------------------------------------------------------------------
; AutoIt Version: 3.0
; Language: English
; Platform: Windows XP
; Function: This script aquires the handles of windows that have taskbar
;          buttons
; Author: Robert Rimes Perry (robertrimesperry@yahoo.com)
; ---------------------------------------------------------------------------

; Constants used with API
Dim Const $GW_OWNER = 4
Dim Const $GWL_EXSTYLE = (-20)
Dim Const $WS_EX_TOOLWINDOW = 0x80
Dim Const $WS_EX_APPWINDOW = 0x40000

; Find windows that:
; - are visible
; - have a title
; - do not have a parent
; - do not have an owner and are not Tool windows OR
;   have an owner and are App windows
Dim $hWnd, $sTitle
Dim $a = WinList()
For $i = 1 to $a[0][0]
    $hWnd = $a[$i][1]
    $sTitle = $a[$i][0]
    $bHasParent = HasParent($hWnd)
    If(IsVisible($hWnd) AND ($sTitle <> "") AND NOT $bHasParent) Then
        $bHasOwner = HasOwner($hWnd)
        $iExStyle = GetExStyle($hWnd)
        If((NOT $bHasOwner AND NOT BitAnd($iExStyle, $WS_EX_TOOLWINDOW)) OR _
        ($bHasOwner AND BitAnd($iExStyle, $WS_EX_APPWINDOW))) Then
            MsgBox(0, "", "sTitle=" & $sTitle & @LF & _
            "hWnd=" & $hWnd & @LF & _
            "bHasParent=" & $bHasParent & @LF & _
            "bHasOwner=" & $bHasOwner & @LF & _
            "iExStyle=" & $iExStyle)
        EndIf
    EndIf
Next

Func GetExStyle($hWnd)
    Local $a = DllCall("user32.dll", "hwnd", "GetWindowLong", _
    "hwnd", $hWnd, _
    "int", $GWL_EXSTYLE)
    Return Dec($a[0])
EndFunc

Func HasOwner($hWnd)
    Local $a = DllCall("user32.dll", "hwnd", "GetWindow", _
    "hwnd", $hWnd, _
    "int", $GW_OWNER)
    If($a[0]) Then
            Return 1
    Else
            Return 0
    EndIf
EndFunc

Func HasParent($hWnd)
    Local $a = DllCall("user32.dll", "hwnd", "GetParent", _
    "hwnd", $hWnd)
    If $a[0] Then
            Return 1
    Else
            Return 0
    EndIf
EndFunc

Func IsMinimized($hWnd)
    If BitAnd(WinGetState($hWnd), 16) Then
        Return 1
    Else
        Return 0
    EndIf
EndFunc


Func IsVisible($hWnd)
    If BitAnd(WinGetState($hWnd), 2) Then
        Return 1
    Else
        Return 0
    EndIf
EndFunc
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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...