gspot Posted May 29, 2014 Share Posted May 29, 2014 Hi, Is there a way to implement an exclude text or title with WinExist, WinWaitActive, etc? Thanks Link to comment Share on other sites More sharing options...
FireFox Posted May 29, 2014 Share Posted May 29, 2014 Hi, What about the Not operator ? If Not WinExists(...) Then Br, FireFox. Link to comment Share on other sites More sharing options...
jguinch Posted May 29, 2014 Share Posted May 29, 2014 You can also use a regular expression in the window title parameter : http://www.autoitscript.com/autoit3/docs/intro/windowsadvanced.htm Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
gspot Posted May 29, 2014 Author Share Posted May 29, 2014 Can some one give me an example code? Thanks for the replys Link to comment Share on other sites More sharing options...
jguinch Posted May 29, 2014 Share Posted May 29, 2014 Give us an example of what you'd like to exclude, instead. Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
gspot Posted May 29, 2014 Author Share Posted May 29, 2014 (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 May 29, 2014 by gspot Link to comment Share on other sites More sharing options...
jdelaney Posted May 29, 2014 Share Posted May 29, 2014 (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 May 29, 2014 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 More sharing options...
Sori Posted May 29, 2014 Share Posted May 29, 2014 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 More sharing options...
gspot Posted May 29, 2014 Author Share Posted May 29, 2014 I was hoping there was an easier way to do that. Thanks for the answers. Link to comment Share on other sites More sharing options...
jdelaney Posted May 29, 2014 Share Posted May 29, 2014 (edited) Not really, example: expandcollapse popup#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 May 29, 2014 by jdelaney gspot 1 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 More sharing options...
Solution jguinch Posted May 29, 2014 Solution Share Posted May 29, 2014 (edited) Maybe I'm late, but here is my function _WinListExclude. expandcollapse popup; #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 May 29, 2014 by jguinch gspot 1 Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
gspot Posted May 30, 2014 Author Share Posted May 30, 2014 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.... Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now