Jump to content

WinList() With Multiple Regex Statements


Go to solution Solved by tantrim,

Recommended Posts



I'm attempting to find either of 2 different windows via regex and WinList(). The first window I would like to get by REGEXPTITLE, the 2nd by REGEXPCLASS. Alone both statements work.
I'm required to use Title and Class in some scenario's so that is the solution I'm looking for. Sometimes one window requires a Title search and another requires a Class search, but I'd like them to be in the same WinList object.

Below is how I would like to accomplish it. But the syntax isn't valid to my knowledge

; OR statement doesn't work.
Local $regex = "[REGEXPTITLE:(?i)(.* — Mozilla Firefox)|REGEXPCLASS:(?i)(SunAwtFrame)]"
Local $winList = WinList($regex)

Other solutions that come with inherent flaws.

; other possible solutions

; Join 2 lists - doesn't retain history accurately
local $winListOne = WinList("[REGEXPTITLE:(?i)(.* — Mozilla Firefox)]")
Local $winListTwo = WinList("[REGEXPCLASS:(?i)(SunAwtFrame)]")
; TODO - add count together to first array and remove count row from 2nd array. Join both arrays 

; Returns over 200 windows
$windows = WinList()
  For $i = 1 To $windows[0][0]
    If StringRegExp($windows[$i][0], "[REGEXPTITLE:(?i)(.* — Mozilla Firefox)]") = 1 Then
    MsgBox(0,0,$windows[$i][0])
  EndIf
Next

; Correctly returns titles with Mozilla, but could return undesirable windows
; MAIN ISSUE is I'm unsure how to use CLASS regex with this method
$windows = WinList()
  For $i = 1 To $windows[0][0]
    If StringRegExp($windows[$i][0], "(.* — Mozilla Firefox)") = 1 Then
    MsgBox(0,0,$windows[$i][0])
  EndIf
Next


Another questions, how does REGEXPCLASS work on WinList() whenever it only returns a Title and Handle column?
image.png.6443256048dfc1af80c4fd7a787ae069.png


Similar Thread: using winlist to create array with multiple titles

Edited by tantrim
Link to post
Share on other sites

Maybe this ?

#include <Array.au3>

Local $aWinList = WinList("[REGEXPTITLE:(?i)(.*Google Chrome.*)]")
_ArrayDisplay($aWinList)
Local $aTemp = WinList("[CLASS:Chrome_WidgetWin_1]")
_ArrayDisplay($aTemp)

_ArrayConcatenate($aWinList, $aTemp, 1)
$aWinList = _ArrayUnique($aWinList, 0, 1, 1, $ARRAYUNIQUE_COUNT)
_ArrayDisplay($aWinList)

Edit : you do not need to use REGEXPCLASS if you search for a specific class

Edited by Nine
Link to post
Share on other sites
31 minutes ago, Nine said:

Maybe this ?

#include <Array.au3>

Local $aWinList = WinList("[REGEXPTITLE:(?i)(.*Google Chrome.*)]")
_ArrayDisplay($aWinList)
Local $aTemp = WinList("[CLASS:Chrome_WidgetWin_1]")
_ArrayDisplay($aTemp)

_ArrayConcatenate($aWinList, $aTemp, 1)
$aWinList = _ArrayUnique($aWinList, 0, 1, 1, $ARRAYUNIQUE_COUNT)
_ArrayDisplay($aWinList)

Edit : you do not need to use REGEXPCLASS if you search for a specific class

1. Thanks for the reply and help.
2. CLASS should suffice then.
3. The solution is close, but it doesn't retain the Order Active/Focused History that a single WinList() will.

The order active/focused history is important for me as I want traverse through past used applications and would like to go in order of history

Edited by tantrim
Link to post
Share on other sites

bad terminology on my part, sorry.

The list is built in the order the windows were last active. The more recent the window was active/focused, the lower the index.

WinList() acts in the same way as your browser does with "go forward one page" and "go backwards one page". - Confusing
 

Edited by tantrim
Link to post
Share on other sites

If I understand you correctly, you would like to have the list of all instances of your browser in the order of their creation (date/time start of the instance), right ?

Link to post
Share on other sites

Sorry I am not following you at all.  The CLASS information is always the same, how would it be useful ?  Why do need to search by class and by title, is only one of them enough since you are looking at the exact same windows ?  WinList always give you in order of last active, isn't that what you want ?

Link to post
Share on other sites

I use 2 IDE's. Rider and Visual Studio.

Visual Studio Window Info:

image.png.30726c28c6451ee49a500d3d8a2cc938.png

Rider Window Info:
image.png.4746a3cb3c32fa3fb2ebf64b9269dabe.png

I want to target Rider with it's Class, and Visual Studio with it's title.

I want to put all of my IDE's in the same WinList() so I can iterate through the list and Activate my IDE's 1 by 1 until I arrive at the IDE I want active.

The history is important to me because I don't want to open up an IDE I haven't opened recently as my first item.

 

; Join 2 lists - doesn't retain history accurately
local $winListOne = WinList("[REGEXPTITLE:(?i)(.*- Microsoft Visual Studio)]")
Local $winListTwo = WinList("[REGEXPCLASS:(?i)(SunAwtFrame)]")
; TODO - add count together to first array and remove count row from 2nd array. Join both arrays 


; MAIN ISSUE is I'm unsure how to use CLASS regex with this method
$windows = WinList()
; $windows object no longer contains class data (to my knowledge) so this doesn't work for class search  
  For $i = 1 To $windows[0][0]
    If StringRegExp($windows[$i][0], "CLASS:SunAwtFrame") = 1 Then
    MsgBox(0,0,$windows[$i][0])
  EndIf
Next

 

EDIT: okay so after rereading what you said about WinList always have the class info I didn't really understand. The for loop statement checks the Title value and not the handle. Upon further research I see that _WinAPI_GetClassName exists and I might be able to get the class from the handle this way.

Edited by tantrim
Link to post
Share on other sites
  • Solution

So I think I figured it out. Thanks for your help @Nine. I would of preferred one line regex expression so I don't have to rework my other code but I can't think of a way.

 

Local $newWinList[1][2]
$windows = WinList()
For $i = 1 To $windows[0][0]
    $class = _WinAPI_GetClassName($windows[$i][1])
    $title = $windows[$i][0]

    If StringRegExp($class, "SunAwtFrame") = 1 Or StringRegExp($title, "- Microsoft Visual Studio") = 1 Then
        $newWinList[0][0] += 1
        _ArrayAdd($newWinList, $windows[$i][0] & "|" & $windows[$i][1])
    EndIf
Next

When pulling the handle from the list it is stored as a string. If you want to reuse the handle make sure to cast it into an HWnd object like below
 

$hWndString = $newWinList[1][1]
$hWnd = HWnd($hWndString)

WinActivate($hWnd)

 

Edited by tantrim
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...