Jump to content

WinExist with exclude text/title


Go to solution Solved by jguinch,

Recommended Posts

Give us an example of what you'd like to exclude, instead.

 

In my scripts its usual to have to deal with similar windows (with same title), a way to distinguish them is by the visible text.

So what i need is a kind of WinExists ( "title" [, "text"] [, "Exclude text"])

where windows with "Exclude text" (a string of some source) in the text will not be considered.

 

 

Edited by gspot
Link to comment
Share on other sites

Use WinList, with the title...loop through the returned array, and look for your window you want to work with (by checking on wingettext, wingetstate, etc)

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

I also recommend using handles if you're dealing with multiple windows with the same titles.

If you need help with your stuff, feel free to get me on my Skype.

I often get bored and enjoy helping with projects.

Link to comment
Share on other sites

Not really, example:

#include <WinAPI.au3>
#include <WinAPIex.au3>
$iProcesses = 5
Enum $iProcesses_PID, $iProcesses_Hwnd, $iProcesses_UBound
Local $aProcesses[$iProcesses][$iProcesses_UBound]

For $i = 0 To UBound($aProcesses)-1
    $aProcesses[$i][$iProcesses_PID] = Run("notepad")
    $a = ""
    While Not IsArray($a)
        $a = _WinAPI_EnumProcessWindows($aProcesses[$i][$iProcesses_PID],True)
    WEnd
    $aProcesses[$i][$iProcesses_Hwnd] = $a[1][0]
    WinMove($aProcesses[$i][$iProcesses_Hwnd],"",($i*80), ($i*80))
Next

For $i = 0 To UBound($aProcesses)-1
    ; cascade a bit
    WinActivate($aProcesses[$i][$iProcesses_Hwnd])
    WinWaitActive($aProcesses[$i][$iProcesses_Hwnd])
    ControlSend($aProcesses[$i][$iProcesses_Hwnd],"","Edit1", "Testing" & $i)
Next

; Activate first window
WinActivate($aProcesses[0][$iProcesses_Hwnd])

$sTextToNOTFind = "Testing0" ; this will get the second window
$a = WinList("[CLASS:Notepad]")
For $i = 1 To UBound($a) - 1
    If Not StringInStr(WinGetText($a[$i][1]),$sTextToNOTFind) Then
        WinActivate($a[$i][1])
        WinWaitActive($a[$i][1])
        ControlSend($a[$i][1],"","Edit1", @CR & "This is more text on the window WITHOUT text=[" & $sTextToNOTFind & "]")
    EndIf
Next

For $i = 0 To UBound($aProcesses)-1
    WinActivate($aProcesses[$i][$iProcesses_Hwnd])
Next

MsgBox(1,1,"close this to close notepad(s)")

For $i = 0 To UBound($aProcesses)-1
    ProcessClose($aProcesses[$i][$iProcesses_PID])
Next
Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

  • Solution

Maybe I'm late, but here is my function _WinListExclude.

; #EXAMPLE# =====================================================================================================================
#Include <Array.au3>
; Open 3 notepad
Local $aPids[3] = [ Run("notepad.exe"), Run("notepad.exe"), Run("notepad.exe") ]

; Send text in a Notepad window
$hNotepad = WinWait("[CLASS:Notepad]")
ControlSetText("[CLASS:Notepad]", "", "Edit1", "This is some text")

; List all Notepad windows (based on class) an exclude the text "some"
Local $aList = _WinListExclude("[CLASS:Notepad]", "some", 2)


_ArrayDisplay($aList)
For $i = 0 To Ubound($aPids) - 1
    ProcessClose($aPids[$i])
Next
; ===============================================================================================================================




; #FUNCTION# ====================================================================================================================
; Name ..........: _WinListExclude
; Description ...: Retrieves a list of windows, esxcluding windows titles or/and text.
; Syntax ........: _WinListExclude([$sTitle = ""[, $sText = ""[, $iFlag = 0]]])
; Parameters ....: $sTitle   - [optional] The title/hWnd/class of the windows to get or exclude the list. Default is "".
;                  $sText    - [optional] The text of the windows to get or exclude the list. Default is "".
;                  $iFlag    - [optional] Specifies whether to exclude titles, text or both. Default is 0.
;                    0 - Do not exlude anything
;                    1 - Exclude titles only
;                    2 - Exclude text only
;                    1 - Exclude both
; Return values .: Returns an array of matching window titles and handles. (See remarks).
; Remarks .......: The array returned is two-dimensional and is made up as follows:
;   $aArray[0][0] = Number of windows returned
;   $aArray[1][0] = 1st window title
;   $aArray[1][1] = 1st window handle (HWND)
;   $aArray[2][0] = 2nd window title
;   $aArray[2][1] = 2nd window handle (HWND)
; ===============================================================================================================================
Func _WinListExclude($sTitle = "", $sText = "", $iFlag = 0)
    Local $n = 1
    Local $iFound

    If NOT IsNumber($iFlag) Or $iFlag < 0 Or $iFlag > 3 Then Return SetError(1, 0, 0)
    If NOT $iFlag Then Return WinList($sTitle, $sText)

    Local $aResult = WinList()
    Local $aWinFilter = WinList($sTitle)

    If BitAND($iFlag, 1) Then
        For $i = 1 To $aResult[0][0]
            $iFound = 0
            For $j = 1 To $aWinFilter[0][0]
                If $aResult[$i][1] = $aWinFilter[$j][1] Then
                    $iFound = 1
                    ExitLoop
                EndIf
            Next

            If NOT $iFound Then
                $aResult[$n][0] = $aResult[$i][0]
                $aResult[$n][1] = $aResult[$i][1]
                $n += 1
            EndIf
        Next
        Redim $aResult[$n][2]
        $aResult[0][0] = UBound($aResult) - 1
    Else
        $aResult = $aWinFilter
    EndIf

    $n = 1
    For $i = 1 To $aResult[0][0]
        $iFound = 0
        If BitAND($iFlag, 2) Then
            If StringInStr( WinGetText($aResult[$i][1]), $sText) Then
                $iFound = 1
            EndIf
        ElseIf NOT StringInStr( WinGetText($aResult[$i][1]), $sText) Then
            $iFound = 1
        EndIf

        If NOT $iFound Then
            $aResult[$n][0] = $aResult[$i][0]
            $aResult[$n][1] = $aResult[$i][1]
            $n += 1
        EndIf
    Next

    Redim $aResult[$n][2]
    $aResult[0][0] = UBound($aResult) - 1

    Return $aResult
EndFunc ; ===> _WinListExclude
Edited by jguinch
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...