Sardar Agabejli
Sardar Agabejli

Reputation: 433

Check if WinList() contains a certain title

I am listing all open windows using WinList() to get window title and -handle in AutoIt.

I want to check if resulting array contains a specific title. What is the best way to do this? There is no WinList().Contains("TitleName") or something like that.

Local $aList = WinList()    ;Gets a list of Window Titles and IDs

Upvotes: 2

Views: 1835

Answers (3)

user4157124
user4157124

Reputation: 2904

Window exists?

"I am listing all open windows … I want to check if … contains a specific title. What is the best way to do this?"

As per Documentation - Function Reference - WinExists() :

Checks to see if a specified window exists.

Example.

Global Const $g_sWndTitle = 'Window title here'

If WinExists($g_sWndTitle) Then WinFlash($g_sWndTitle)

Retrieve window handle, -text and -title

Handle

"… to get window title and -handle …"

As per Documentation - Function Reference - WinGetHandle() :

Retrieves the internal handle of a window.

Example:

Global Const $g_sWndTitle = 'Window title here'
Global       $g_hWnd

If WinExists($g_sWndTitle) Then

    $g_hWnd = WinGetHandle($g_sWndTitle)
    WinFlash($g_hWnd)

EndIf

Text

As per Documentation - Function Reference - WinGetText() :

Retrieves the text from a window.

Example:

Global Const $g_sWndTitle = 'Window title here'

If WinExists($g_sWndTitle) Then

    WinFlash($g_sWndTitle)
    ConsoleWrite(WinGetText($g_sWndTitle) & @CRLF)

EndIf

Title

Likewise, WinGetTitle().

Upvotes: 0

Xenobiologist
Xenobiologist

Reputation: 2151

You could also use something similar to what you wrote.

#include <Array.au3>
Opt("WinDetectHiddenText", 0) ;0=don't detect, 1=do detect
Opt("WinSearchChildren", 0) ;0=no, 1=search children also
Opt("WinTextMatchMode", 1) ;1=complete, 2=quick
Opt("WinTitleMatchMode", 1) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase
Local $title = 'AutoIt Help (v3.3.14.2)'
Local $aList = WinList()
;~ _ArrayDisplay($aList)
Local $iIndex = _ArraySearch($aList,$title)
WinActivate($aList[$iIndex][1], '')

Upvotes: 1

Sardar Agabejli
Sardar Agabejli

Reputation: 433

OK, I got it now:

For $i = 1 To $aList[0][0]
    If $aList[$i][0] = "Title/String you search for" Then
        MsgBox($MB_SYSTEMMODAL, "", "MessageBox shows this text if title is in list.")
    EndIf
Next

Upvotes: 2

Related Questions