Jump to content

Script to list current windows


qwert
 Share

Recommended Posts

Has anyone written a script to list all current windows by Handle and Title? I've searched these forums without success -- although I'm not absolutely sure what search terms to use.

I know I can get the active window using WinGetHandle("") and WinGetTitle(""). What I need is the handle and title of all current windows (the ones with entries on the windows taskbar).

Thanks for any help.

Update: I've located the WinList() function which provides the detail, but not packaged in a summary format. Does such a utility exist?

Edited by qwert
Link to comment
Share on other sites

Has anyone written a script to list all current windows by Handle and Title? I've searched these forums without success -- although I'm not absolutely sure what search terms to use.

I know I can get the active window using WinGetHandle("") and WinGetTitle(""). What I need is the handle and title of all current windows (the ones with entries on the windows taskbar).

Thanks for any help.

Update: I've located the WinList() function which provides the detail, but not packaged in a summary format. Does such a utility exist?

Here's a snippet that I frequently use. To isolate just the visible (e.g., the "non-minimized") windows, uncomment the extra "If" statement in the _IsVisible() function. Tweak to your liking :)

CODE

#include <Array.au3>

_GetWindows()

Func _GetWindows()

Dim $VisibleWindows[1] = ["0"]

$AllWindows = WinList()

;_ArrayDisplay($AllWindows,"All Windows")

For $i = 1 To $AllWindows[0][0]

If IsVisible($AllWindows[$i][1]) Then

If $AllWindows[$i][0] <> "" And $AllWindows[$i][0] <> "Program Manager" Then

ReDim $VisibleWindows[uBound($VisibleWindows) + 1]

$VisibleWindows[0] = $VisibleWindows[0] + 1

$VisibleWindows[$VisibleWindows[0]] = $AllWindows[$i][0]

EndIf

Else

EndIf

Next

_ArrayDisplay($VisibleWindows,"Visible Windows")

EndFunc

Func IsVisible($handle)

If BitAND(WinGetState($handle), 4) Then

;If Not BitAND(WinGetState($handle), 16) Then

If BitAND(WinGetState($handle), 2) Then

Return 1

Else

Return 0

EndIf

;EndIf

EndIf

EndFunc

- MoChr(77)& Chr(97)& Chr(100)& Chr(101)& Chr(32)& Chr(121)& Chr(97)& Chr(32)& Chr(108)& Chr(111)& Chr(111)& Chr(107)-------I've told you 100,000 times not to exaggerate!-------Don't make me hit you with my cigarette hand...-------My scripts:Random Episode Selector, Keyboard MouseMover, CopyPath v2.1, SmartRename for XP,Window Tracer[sup]New![/sup]

Link to comment
Share on other sites

Monamo, thanks. That's just the type of tabular summary I was looking for. But since I'm not familiar with displaying arrays, can you explain how to add the window handles to the summary? A clear and useful example like this goes a long way to helping me (and others, I presume) get a foothold toward understanding the different areas of scripting. Your help is appreciated.

Link to comment
Share on other sites

Monamo, thanks. That's just the type of tabular summary I was looking for. But since I'm not familiar with displaying arrays, can you explain how to add the window handles to the summary? A clear and useful example like this goes a long way to helping me (and others, I presume) get a foothold toward understanding the different areas of scripting. Your help is appreciated.

To add the handles, you'd just want to change the array to a 2-dimensional array and throw in the corresponding window handles as each title is added. Using the example from my post above, just replace the _GetWindows() function with this version:

CODE
Func _GetWindows()

Dim $VisibleWindows[1][2] = [["0",""]]

$AllWindows = WinList()

For $i = 1 To $AllWindows[0][0]

If IsVisible($AllWindows[$i][1]) Then

If $AllWindows[$i][0] <> "" And $AllWindows[$i][0] <> "Program Manager" Then

ReDim $VisibleWindows[uBound($VisibleWindows) + 1][2]

$VisibleWindows[0][0] = $VisibleWindows[0][0] + 1

$VisibleWindows[($VisibleWindows[0][0])][0] = $AllWindows[$i][0]

$VisibleWindows[($VisibleWindows[0][0])][1] = $AllWindows[$i][1]

EndIf

Else

EndIf

Next

_ArrayDisplay($VisibleWindows,"Visible Windows")

EndFunc

- MoChr(77)& Chr(97)& Chr(100)& Chr(101)& Chr(32)& Chr(121)& Chr(97)& Chr(32)& Chr(108)& Chr(111)& Chr(111)& Chr(107)-------I've told you 100,000 times not to exaggerate!-------Don't make me hit you with my cigarette hand...-------My scripts:Random Episode Selector, Keyboard MouseMover, CopyPath v2.1, SmartRename for XP,Window Tracer[sup]New![/sup]

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