Sign in to follow this  
Followers 0
gspot

WinExist with exclude text/title

12 posts in this topic

Hi,

Is there a way to implement an exclude text or title with WinExist, WinWaitActive, etc?

Thanks

 

Share this post


Link to post
Share on other sites



Hi,

What about the Not operator ?

If Not WinExists(...) Then

 

Br, FireFox.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

Can some one give me an example code?

Thanks for the replys

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

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.

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

I was hoping there was an easier way to do that.

Thanks for the answers.

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

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
1 person likes this

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.

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

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
1 person likes this

Share this post


Link to post
Share on other sites

Thanks jguinch and jdelaney really helpfull. I sugest that a UDF of this type should be integrated in to the helpfile. For me and my scripts a "Excludetext" or even "ExcludeTitle" function are fundamental tools to make them more robust....

Share this post


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
Sign in to follow this  
Followers 0