logcomptechs Posted November 23, 2010 Posted November 23, 2010 (edited) Have two questions involving WinExist and WinClose. First I am trying to see if 28 windows exist, they all have the same name and only the number changes after the name (example: window1, window2, etc...). So far what I have is, when I launch the program, it seems to detect if (example: window14) does not exist, then it calls the function. But after it is done checking all 28 windows exist, then it checks to see if any windows disappeared, it does not detect missing windows again, or at least not all the time. This is the code I am using as of now, maybe it can be improved or there is a better way? While 1 $count = 1 Sleep(100) Do If WinExist("window" & $count) = 0 Then Call("function") EndIf $count = $count + 1 Until $count = 28 WEnd Second question, trying to close all windows with a certain name, but I do not know how many windows are present at any given time. So right now just have it count 28 times (cause that is the max number of times this window could be open). Does not to work very well ether, cause, leave the program running, come back to it, windows with that name will still be there, so wondering if there is a better way? While 1 $close = 1 Sleep(100) Do WinClose("thewindow", "") Sleep(100) $close = $close +1 Until $close = 28 WEnd Edited November 23, 2010 by logcomptechs
PsaltyDS Posted November 23, 2010 Posted November 23, 2010 You might try WinList() and use the array of window handles. That would be much more reliable: $aWinList = WinList("AutoIt") For $n = 1 to $aWinList[0][0] ConsoleWrite($n & ": hWnd = " & $aWinList[$n][1] & "; Title = " & $aWinList[$n][0] & @LF) Next Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
logcomptechs Posted November 23, 2010 Author Posted November 23, 2010 Would I do this to check if the window does not exist then? For $n = 1 to $aWinList[0][0] If WinExist($aWinList) = 0 Then Call("function") EndIf Next
PsaltyDS Posted November 23, 2010 Posted November 23, 2010 No, that's a 2D array with the count in [0][0], if there are no matches then [0][0] = 0: $aWinList = WinList("AutoIt") If $aWinList[0][0] Then For $n = 1 To $aWinList[0][0] ConsoleWrite($n & ": hWnd = " & $aWinList[$n][1] & "; Title = " & $aWinList[$n][0] & @LF) Next Else MsgBox(16, "Error", "No matching windows found.") EndIf Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
logcomptechs Posted November 23, 2010 Author Posted November 23, 2010 I see, so this would be the same thing then? $aWinList = WinList("AutoIt") If Not $aWinList[0][0] Then MsgBox(16, "Error", "No matching windows found.") EndIf
PsaltyDS Posted November 23, 2010 Posted November 23, 2010 Yes. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
logcomptechs Posted November 23, 2010 Author Posted November 23, 2010 Still kinda confused, cause I need to check 1 through 28, lets say window1 is missing, I need to know what number is missing, in order to call my function properly. I understand that this list all available windows, then run through the array 28 times, to see if any numbers are missing?
SadBunny Posted November 23, 2010 Posted November 23, 2010 (edited) /edit: can't seem to remove this even though there is a "Delete" button... This was an accidental double post Edited November 23, 2010 by SadBunny Roses are FF0000, violets are 0000FF... All my base are belong to you.
SadBunny Posted November 23, 2010 Posted November 23, 2010 You can run through the array, but you could also use the array search. I wrote a stupid little test: I opened two notepad ("Kladblok" in Dutch) windows, one with a file1.txt and one with a file3.txt. Say I would want to know in the range test1.txt to test4.txt which windows are not present! (My script should show that 2 and 4 are not present ofcourse.) A way to do that would be: #include <Array.au3> $testarray = WinList("test") _ArrayDisplay($testarray) $amountOfWindowsFound = $testarray[0][0] $resultstring = "" For $i = 1 To 4 $windowThatShouldBeThere = "test" & $i & ".txt - Kladblok" ConsoleWrite($windowThatShouldBeThere & @CRLF) If _ArraySearch($testarray, $windowThatShouldBeThere) == -1 Then $resultstring = $resultstring & $windowThatShouldBeThere & @CRLF EndIf Next MsgBox(64, "test", "Windows not found: " & @CRLF & $resultstring) (Instead of putting it all into a string and msgboxing it you could ofcourse do whatever you want with the information, the point is that this correctly identifies which in the range are, and which are not present.) Is this what you are looking for? Roses are FF0000, violets are 0000FF... All my base are belong to you.
logcomptechs Posted November 23, 2010 Author Posted November 23, 2010 #include <Array.au3> $testarray = WinList("window") For $i = 1 To 28 $windowThatShouldBeThere = "window" & $i If _ArraySearch($testarray, $windowThatShouldBeThere) == -1 Then Call("function") EndIf Next Just simplified it, would that be correct? All I want it to do is if window1 or window23, etc... is missing, then call the function.
SadBunny Posted November 23, 2010 Posted November 23, 2010 (edited) If the windows is actually called exactly "window1" then it looks about right I guess /edit I NEED SLEEP! Edited November 23, 2010 by SadBunny Roses are FF0000, violets are 0000FF... All my base are belong to you.
Tvern Posted November 24, 2010 Posted November 24, 2010 I don't think you want to use Call (you hardly ever need it) #include <Array.au3> $testarray = WinList("window") For $i = 1 To 28 $windowThatShouldBeThere = "window" & $i ;Call is not needed. Just write the function name instead. ;By avoiding Call, you can also pass parameters to a function. Passing the name of the missing window to the function could be usefull If _ArraySearch($testarray, $windowThatShouldBeThere) == -1 Then function($windowThatShouldBeThere) Next Func function($sWinName) ;I'd think of a better name then "function" :) Run("path to exe") ;launch a new window WinWait("old title","") ;wait for the program to launch WinSetTitle("old title","",$sWinName) ;rename that window ;the more reliable way to identify the right window to rename is using winlist and compare PID's. Post again if you need it. EndFunc
logcomptechs Posted November 24, 2010 Author Posted November 24, 2010 Thank you, giving those suggestions a try, to see how they work
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