Jump to content

Help Filtering Windows


Recommended Posts

i need a window filtering function for a boss button tool project that i'm currently planning.

The problem is that i cant filter the apps window.

Here s my window filtering code

CODE

Func FindRealWindows()

$list = WinList()

$c = 0

Dim $wins[1]

For $x = 1 to $list[0][0]

If isVisible($list[$x][1]) And StringStripWS($list[$x][0],3) <> "" Then

If Not($list[$x][0] = "Program Manager") And Not(WinGetTitle($list[$x][1]) = "Boss Script") Then

$c += 1

If $c >= UBound($wins) Then

ReDim $wins[$c+1]

EndIf

$wins[$c] = $list[$x][1]

EndIf

EndIf

Next

return $wins

EndFunc

the Not(WinGetTitle($list[$x][1]) = "Boss Script") Condition doesnt work.

isVisible is that one from the helpfile.

"Boss Script" is the title of my window.

Instead of Not(...) I also tried <> but still no success.

I even tested the condition without the nots outside of this function it returns true if the handle of the apps window is given but although it should end in false because of the not, autoit still runs the code inside of the if

i made 2 ifs after it didnt work because i thought autoit isnt able to handle 3 ands and 4 conditions

can anyone help me finding my mistake?

Link to comment
Share on other sites

Hi, here's a crude example with some comments to hopefully make it easy to follow..

#Include <Array.au3> ; only used for _ArrayDisplay

;Put the window titles you want to exclude in the $ExcludeFilter variable, delimited with |.
;Putting it here at the top of the script just makes it easy to edit the filter.
Global $ExcludeFilter = "Boss Script||Program Manager|Windows Task Manager"

; This will be the 2D array of returned window titles and handles.
; $aCurList[0][0] contains the count of returned windows
; $aCurList[x][0] contains the Title
; $aCurList[x][1] contains the Handle
; (x represents a number from 1 to however many windows returned)
Dim $aCurList[1][2] 

;List all windows
$aWL = WinList()

; Loop through the window list
For $i = 1 To $aWL[0][0]
    
    ; If WindowFilter() returns 1 then we want to keep the title/handle
    If WindowFilter($aWL[$i][1]) Then 
        
        ;Add the window count to $aCurList[0][0]
        $aCurList[0][0] +=1 
        
        ;Redim the array with the new count
        Redim $aCurList[$aCurList[0][0] + 1][2]
        
        ;Add the new Title/Handle to the array 
        $aCurList[Ubound($aCurList) -1][0] = $aWL[$i][0]
        $aCurList[Ubound($aCurList) -1][1] = $aWL[$i][1]
    EndIf
Next    

; Just to see what the $aCurList array is returning
_ArrayDisplay($aCurList)

; Just a modified version of the IsVisable function.
; Using the $ExcludeFilter at the top of the script.
Func WindowFilter($handle)
    ; If the window is visable then ...
    If BitAnd(WinGetState($handle), 2) Then 
        
        ;Declare some local variables
        Local $WGT, $SSF
        
        ; Get the Title of the current window
        $WGT = WinGetTitle($handle)
        
        ;Split the globalExludeFilter into a local array
        $SSF = StringSplit($ExcludeFilter, "|") 
        
        ; Loop through the ExludeFilter titles
        For $f = 1 To $SSF[0]
            
            ; if the ExludeFilter title matches the current window then we don't want it.
            If $WGT = $SSF[$f] Or StringStripWS($WGT, 3) = $SSF[$f] Then Return 0 
        Next
        
        ; If we reach here then we've passed the filter and want to keep the window
        Return 1  
    EndIf
EndFunc

Cheers

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