Jump to content

How to list titles or handles of all open windows


Recommended Posts

Suppose that I want to activate a window but don't know its exact name. Is there a way to loop though and get the window titles so that I can do a string match against the list, and decide which one to activate? I used to do this operation with WinBatch but would like to use AutoIt V3. Thanks!

Link to comment
Share on other sites

Suppose that I want to activate a window but don't know its exact name. Is there a way to loop though and get the window titles so that I can do a string match against the list, and decide which one to activate? I used to do this operation with WinBatch but would like to use AutoIt V3. Thanks!

ProcessList

; List all processes
$list = ProcessList()
for $i = 1 to $list[0][0]
  msgbox(0, $list[$i][0], $list[$i][0])
next
Edited by BigDod


Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

Link to comment
Share on other sites

I created a ProcessList logger for this reason B) Here it is

$output = "ProcessList.txt"
$array = ProcessList()
$a = 0
While $a <> $array[0][0] + 1
     FileWriteLine($output, $array[$a][0] & " " & $array[$a][1])
    $a = $a + 1
WEnd
MsgBox(0, "Done", "All processes listed and logged in file : " & $output)

P.S. Did you get the ProcessList gen idea out of one of my scripts BigDod? I've had it for a long time :o hehe

Edited by AutoIt Smith
Link to comment
Share on other sites

I created a ProcessList logger for this reason B) Here it is

$output = "ProcessList.txt"
$array = ProcessList()
$a = 0
While $a <> $array[0][0] + 1
     FileWriteLine($output, $array[$a][0] & " " & $array[$a][1])
    $a = $a + 1
WEnd
MsgBox(0, "Done", "All processes listed and logged in file : " & $output)

P.S. Did you get the ProcessList gen idea out of one of my scripts BigDod? I've had it for a long time :o hehe

No, I found it in the help files. First place I look.


Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

Link to comment
Share on other sites

Welcome to the forums Keith!

Are you aware that AutoIt does not require the full title of windows in order to manipulate them? Depending on a customisable setting, AutoIt can find windows beginning with a certain string and containing a certain string in addition to exact title matching.

Using WinTitleMatchMode 4 you can also match the active window and you can also identify windows by 'class name' (which can be determined on a per-window basis using the AutoIt Window Info tool).

Please refer to Help > Using AutoIt > Window Titles and Text if this is what you're after.

Edited by LxP
Link to comment
Share on other sites

  • 2 months later...
  • Moderators

The get window names by process has been around for close to 2 years on here I use that one when I want to work with a specific application, but If I just want all windows I use WinList()... you could stick it in a function and call it with AdlibEnable().

;AdlibEnable('GetWindows', 500); checks function ever 500 milliseconds... 250 is default

;#include <Array.au3>
;Local $Test = StringSplit(GetWindows(1), Chr(01))
;_ArrayDisplay($Test, 'array')

Local $Timer = TimerInit()
While 1
    If TimerDiff($Timer) / 1000 >= .5 Then
        MsgBox(0, "", GetWindows())
        $Timer = TimerInit(); start timer over
    EndIf
    Sleep(100)
WEnd

Func GetWindows($ChangeToArray = '0'); call it with a 1 if you want an array
    Local $List = WinList()
    Local $ReturnWindows
    Local $Seperator
    If $ChangeToArray = 0 Then
        $Seperator = @LF
    Else
        $Seperator = Chr(01)
    EndIf
    For $i = 1 to $List[0][0]
        If BitAND(WinGetState($List[$i][1]), 2) And $List[$i][0] <> '' Then $ReturnWindows = $ReturnWindows & $List[$i][0] & $Seperator
    Next
    If $ChangeToArray = 0 Then
        Return StringTrimRight($ReturnWindows, 1); just to show you how it works
    Else
        Return StringTrimRight($ReturnWindows, 1);<< Return it as an array
    EndIf
EndFunc
Commented a few different options, But you should get the general idea Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

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