Rota Posted April 27, 2009 Posted April 27, 2009 Hi Dears, I am getting whacked on working with the windows status, take an example here: When I click to one Button in A window, if there is nothing wrong with the information/system, it will go to B window, while sometimes if there is something wrong with the system, there could be some other error window pops-up, it could be C window or D window, so my question comes to how can I detect the next openning window when I click to the button in A window... I am now using WinExists(xxx) to detect if the window is there, then use WinWaitActive to get control of the window, while the problem is the system has the reponse time, you can't expect it turns to next window immediately when you click to the button, it might take 1-2 s sometimes or even more, so this WinExists won't work at the most of time cause the program works fast while the system response slow... Is there any better solution to help me out, I believe AUTOIT should work good for these kind of jobs of multiple interfaces... Thanks a ton Regards
picea892 Posted April 27, 2009 Posted April 27, 2009 (edited) Hi Dears,I am getting whacked on working with the windows status, take an example here:When I click to one Button in A window, if there is nothing wrong with the information/system, it will go to B window, while sometimes if there is something wrong with the system, there could be some other error window pops-up, it could be C window or D window, so my question comes to how can I detect the next openning window when I click to the button in A window...I am now using WinExists(xxx) to detect if the window is there, then use WinWaitActive to get control of the window, while the problem is the system has the reponse time, you can't expect it turns to next window immediately when you click to the button, it might take 1-2 s sometimes or even more, so this WinExists won't work at the most of time cause the program works fast while the system response slow...Is there any better solution to help me out, I believe AUTOIT should work good for these kind of jobs of multiple interfaces...Thanks a tonRegardsHi,I think you may need to go to the next level if you are getting these types of problems. I used to use a WMI event notifiy. I only have examples in VBS so maybe someone can come along and provide an autoit example. The below link is close and could be tweaked to meet your needshttp://www.autoitscript.com/forum/index.php?showtopic=42580 Edited April 27, 2009 by picea892
Yashied Posted April 27, 2009 Posted April 27, 2009 (edited) Hi Dears,I am getting whacked on working with the windows status, take an example here:When I click to one Button in A window, if there is nothing wrong with the information/system, it will go to B window, while sometimes if there is something wrong with the system, there could be some other error window pops-up, it could be C window or D window, so my question comes to how can I detect the next openning window when I click to the button in A window...I am now using WinExists(xxx) to detect if the window is there, then use WinWaitActive to get control of the window, while the problem is the system has the reponse time, you can't expect it turns to next window immediately when you click to the button, it might take 1-2 s sometimes or even more, so this WinExists won't work at the most of time cause the program works fast while the system response slow...Is there any better solution to help me out, I believe AUTOIT should work good for these kind of jobs of multiple interfaces...Thanks a tonRegardsWhat's wrong with WinWaitActive()? Edited April 27, 2009 by Yashied My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More...
syno Posted April 27, 2009 Posted April 27, 2009 (edited) Hi I use an IF, THEN structure to only execute the next command once a window is active. This for me is the best resolution if you can see the window and it means you do not need to relay on the speed of your environment in order to execute you key strokes in sequence. The code: WinWait("User Sign-In", "") If Not WinActive("User Sign-In", "") Then WinActivate("User Sign-In", "") WinWaitActive("User Sign-In", "") Send("{enter}") Thanks Edited April 27, 2009 by syno
Rota Posted April 27, 2009 Author Posted April 27, 2009 What's wrong with WinWaitActive()?The problem is which window am I going to to WinWaiActive, cause when you click to the button, there could be 3 or even more windows pop-up... if I WinWaitActive(, it will get hanged if B won't pop-up but C comes up...
Rota Posted April 27, 2009 Author Posted April 27, 2009 (edited) Hi I use an IF, THEN structure to only execute the next command once a window is active. This for me is the best resolution if you can see the window and it means you do not need to relay on the speed of your environment in order to execute you key strokes in sequence. The code: WinWait("User Sign-In", "") If Not WinActive("User Sign-In", "") Then WinActivate("User Sign-In", "") WinWaitActive("User Sign-In", "") Send("{enter}") Thanks Same as I replied above, your solution will be only applicable when you make sure what window is going to pop-up after click to the button, then whatif there could be more than 1 window openned after you click the button.... cause you can't winwait (B ) and Winwait(C ) at the same time, right? otherwise the program will get hanged. Edited April 27, 2009 by Rota
syno Posted April 27, 2009 Posted April 27, 2009 Same as I replied above, your solution will be only applicable when you make sure what window is going to pop-up after click to the button, then whatif there could be more than 1 window openned after you click the button.... cause you can't winwait (B ) and Winwait(C ) at the same time, right? otherwise the program will get hanged. Can you not maximise the offending windows, i.e WinSetState ( "User-Sign In", "", @SW_MAXIMIZE )
Moderators Melba23 Posted April 27, 2009 Moderators Posted April 27, 2009 Rota,If you were to poll WinList, you could detect any newly opened windows and get their titles and handles. Then you could determine which one of your many window options had opened and go on from there.Here is a little proof-of-concept script that pops up a list of newly opened windows when a new window is opened (surprising how many are needed!):#include <Array.au3> $aList1 = WinList() While 1 $aList2 = WinList() If $aList2[0][0] <> $aList1[0][0] Then If $aList2[0][0] > $aList1[0][0] Then Local $aList3[1] For $i = 1 To $aList2[0][0] If _ArraySearch($aList1, $aList2[$i][1], 0, 0, 0, 0, 1, 1) = -1 Then _ArrayAdd($aList3, $aList2[$i][0]) ; [0] for titles or [1] for handles $aList3[0] += 1 EndIf Next _ArrayDisplay($aList3) EndIf $aList1 = $aList2 EndIf WEndI hope this is useful.M23  Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Â
ChrisL Posted April 27, 2009 Posted April 27, 2009 If you know it's a choice between 2 or 3 windows then you could do this. $Next_Window = "" While 1 Select Case WinExists("Window B Name") $Next_Window = "B" Exitloop Case WinExists("Window C Name") $Next_Window = "C" Exitloop Case WinExists("Window D Name") $Next_Window = "D" Exitloop EndSelect Sleep(200) WEnd Msgbox(0,"","Next window is " & $Next_Window) [u]Scripts[/u]Minimize gui to systray _ Fail safe source recoveryMsgbox UDF _ _procwatch() Stop your app from being closedLicensed/Trial software system _ Buffering Hotkeys_SQL.au3 ADODB.Connection _ Search 2d Arrays_SplashTextWithGraphicOn() _ Adjust Screen GammaTransparent Controls _ Eventlogs without the crap_GuiCtrlCreateFlash() _ Simple Interscript communication[u]Websites[/u]Curious Campers VW Hightops Lambert Plant Hire
Rota Posted April 27, 2009 Author Posted April 27, 2009 Rota, If you were to poll WinList, you could detect any newly opened windows and get their titles and handles. Then you could determine which one of your many window options had opened and go on from there. Here is a little proof-of-concept script that pops up a list of newly opened windows when a new window is opened (surprising how many are needed!):#include <Array.au3> $aList1 = WinList() While 1 $aList2 = WinList() If $aList2[0][0] <> $aList1[0][0] Then If $aList2[0][0] > $aList1[0][0] Then Local $aList3[1] For $i = 1 To $aList2[0][0] If _ArraySearch($aList1, $aList2[$i][1], 0, 0, 0, 0, 1, 1) = -1 Then _ArrayAdd($aList3, $aList2[$i][0]); [0] for titles or [1] for handles $aList3[0] += 1 EndIf Next _ArrayDisplay($aList3) EndIf $aList1 = $aList2 EndIf WEnd I hope this is useful. M23 Thanks Melba23, actually I also thought the same before while never put it into practice, will try this later and get back to here...
Rota Posted April 27, 2009 Author Posted April 27, 2009 If you know it's a choice between 2 or 3 windows then you could do this. $Next_Window = "" While 1 Select Case WinExists("Window B Name") $Next_Window = "B" Exitloop Case WinExists("Window C Name") $Next_Window = "C" Exitloop Case WinExists("Window D Name") $Next_Window = "D" Exitloop EndSelect Sleep(200) WEnd Msgbox(0,"","Next window is " & $Next_Window) Thanks, while whenever there is a system response issue, this solution won't work, for example, we expect window C will open after we click to the button, while system response slow, and this window C delay to be openned after 3 s, so the program will winExists the Current window A(in the case clicking button it won't pop-up new window, it remains in Window A), unless we always have the pop-up, this will work, the problem is whatif we don't have extra pop-up window, Window A only refresh itself, how do we detect it?
ChrisL Posted April 27, 2009 Posted April 27, 2009 Thanks, while whenever there is a system response issue, this solution won't work, for example, we expect window C will open after we click to the button, while system response slow, and this window C delay to be openned after 3 s, so the program will winExists the Current window A(in the case clicking button it won't pop-up new window, it remains in Window A), unless we always have the pop-up, this will work, the problem is whatif we don't have extra pop-up window, Window A only refresh itself, how do we detect it? You don't have Window A in as an option in the while loop. You set $Next_Window = "A" You add a timer and if none of the other windows appear before the timeout then the $Next_Window variable remains as Window A $Next_Window = "A" $Timer = TimerInit() While 1 Select Case WinExists("Window B Name") $Next_Window = "B" Exitloop Case WinExists("Window C Name") $Next_Window = "C" Exitloop Case WinExists("Window D Name") $Next_Window = "D" Exitloop EndSelect If TimerDiff($Timer) > 10000 then Exitloop;10 Seconds Sleep(200) WEnd [u]Scripts[/u]Minimize gui to systray _ Fail safe source recoveryMsgbox UDF _ _procwatch() Stop your app from being closedLicensed/Trial software system _ Buffering Hotkeys_SQL.au3 ADODB.Connection _ Search 2d Arrays_SplashTextWithGraphicOn() _ Adjust Screen GammaTransparent Controls _ Eventlogs without the crap_GuiCtrlCreateFlash() _ Simple Interscript communication[u]Websites[/u]Curious Campers VW Hightops Lambert Plant Hire
Rota Posted April 28, 2009 Author Posted April 28, 2009 You don't have Window A in as an option in the while loop. You set $Next_Window = "A" You add a timer and if none of the other windows appear before the timeout then the $Next_Window variable remains as Window A $Next_Window = "A" $Timer = TimerInit() While 1 Select Case WinExists("Window B Name") $Next_Window = "B" Exitloop Case WinExists("Window C Name") $Next_Window = "C" Exitloop Case WinExists("Window D Name") $Next_Window = "D" Exitloop EndSelect If TimerDiff($Timer) > 10000 then Exitloop;10 Seconds Sleep(200) WEnd Thanks ChrisL, in that case don't you think it would be really time-consuming if the system is working fine, it always need to wait for 10s when there is no extra new windows pop-up... Can you try optimizing it?
Rota Posted April 28, 2009 Author Posted April 28, 2009 Rota, If you were to poll WinList, you could detect any newly opened windows and get their titles and handles. Then you could determine which one of your many window options had opened and go on from there. Here is a little proof-of-concept script that pops up a list of newly opened windows when a new window is opened (surprising how many are needed!):#include <Array.au3> $aList1 = WinList() While 1 $aList2 = WinList() If $aList2[0][0] <> $aList1[0][0] Then If $aList2[0][0] > $aList1[0][0] Then Local $aList3[1] For $i = 1 To $aList2[0][0] If _ArraySearch($aList1, $aList2[$i][1], 0, 0, 0, 0, 1, 1) = -1 Then _ArrayAdd($aList3, $aList2[$i][0]); [0] for titles or [1] for handles $aList3[0] += 1 EndIf Next _ArrayDisplay($aList3) EndIf $aList1 = $aList2 EndIf WEnd I hope this is useful. M23 I tried the same as you provided, the same problem we faced is if we don't new extra window pop-up, then this loop won't work...cause $aList1[0][0]==$aList2[0][0]...
Rota Posted April 28, 2009 Author Posted April 28, 2009 Just want to reiterate/recap the issue here therefore for better solution coming up.... If we click a Button in Window A to refresh the window/page... Scenario 1: No Error Occurs. Window A refresh successfully. Scenario 2: 1st Error Occurs. Window A not refreshed, Window B(error window) pop-up. Scenario 3: 2nd Error Occurs. Window A not refreshed, Window C(error window) pop-up. Scenario 4: 3rd Error Occurs. Window A not refreshed, Window D(error window) pop-up. Special situation: System responses slow, all scenario are delayed for several second. Then how can we detect all scenario?
herewasplato Posted April 28, 2009 Posted April 28, 2009 (edited) Let me back up to one thing that you stated/questioned:"... cause you can't winwait (B ) and Winwait(C ) at the same time, right? otherwise the program will get hanged."You can, but it is not much different than what ChrisL did with WinExists...winWait timeouts prevent the "hang".while 1if winwait(B,"",1) or winwait (C,"",1) or winwait(D,"",1) then exitloopwendI'm not saying that this will help you do what you want - I'm just addressing that statement/question.You might find a solution using the adlib function - but it would be nice to know if there is some info that changes in window (A) Like:window (A, "text before refresh");code to request refreshwindow (A, "during refresh")while 1 if window (A, "text after refresh", 1) or winwait(B,"",1) or winwait (C,"",1) or winwait(D,"",1) then exitloop wend Again, the code that ChrisL or Melba23 provided is more useful since you will know which window appeared... but I thought that I would toss this in along with adlib.So - is there any text likewindow (A, "text before refresh") and window (A, "during refresh")Edit: I see know where you stated that Window ( is the refresh of Window (A) - sorry missed that in the OP. Edited April 28, 2009 by herewasplato [size="1"][font="Arial"].[u].[/u][/font][/size]
herewasplato Posted April 28, 2009 Posted April 28, 2009 (edited) ... it always need to wait for 10s when there is no extra new windows pop-up...How do you figure that?In your OP you said:"When I click to one Button in A window, if there is nothing wrong with the information/system, it will go to B window,"In your recap, window B is an errorWhich is it? Edited April 28, 2009 by herewasplato [size="1"][font="Arial"].[u].[/u][/font][/size]
herewasplato Posted April 28, 2009 Posted April 28, 2009 (edited) One last post and I'll let you chew of all of my ramblings: $Next_Window = "A" ;code to request the refresh of Window A WinWait("Window A Name", "text during refresh") ;or even a pixel function to detect the "awaiting refresh state" While 1 Select Case WinExists("Window A Name", "has refreshed") ExitLoop Case WinExists("Window B Name") $Next_Window = "B" ExitLoop Case WinExists("Window C Name") $Next_Window = "C" ExitLoop Case WinExists("Window D Name") $Next_Window = "D" ExitLoop EndSelect Sleep(200) WEndIf you are positive that these are the only windows that you will see AND you can do a winwait for the middle of a refresh of window A then you do not need a timer... unless you just want one for window E that you did not foresee :-) Edited April 28, 2009 by herewasplato [size="1"][font="Arial"].[u].[/u][/font][/size]
Rota Posted April 28, 2009 Author Posted April 28, 2009 How do you figure that?In your OP you said:"When I click to one Button in A window, if there is nothing wrong with the information/system, it will go to B window,"In your recap, window B is an errorWhich is it?Sorry for the typo... it should be read as " Click the Button in A window to refresh else pop-up B,C... window if there is an error occur.."
Rota Posted April 28, 2009 Author Posted April 28, 2009 One last post and I'll let you chew of all of my ramblings: $Next_Window = "A" ;code to request the refresh of Window A WinWait("Window A Name", "text during refresh") ;or even a pixel function to detect the "awaiting refresh state" While 1 Select Case WinExists("Window A Name", "has refreshed") ExitLoop Case WinExists("Window B Name") $Next_Window = "B" ExitLoop Case WinExists("Window C Name") $Next_Window = "C" ExitLoop Case WinExists("Window D Name") $Next_Window = "D" ExitLoop EndSelect Sleep(200) WEndIf you are positive that these are the only windows that you will see AND you can do a winwait for the middle of a refresh of window A then you do not need a timer... unless you just want one for window E that you did not foresee :-) Thanks herewasplato, this sounds working this time, would look for if there is any text I could define it as "before/during/after refresh" status..
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