jdelaney Posted July 16, 2012 Share Posted July 16, 2012 I've had troubles with WinWait...not sure about anyone else...Such as, I initiate an app, and perform a winwait, and the application is present, but winwait fails (almost like it doesn't refresh the current applications). Ever since, I have instead done loops of WinExists: $iWaitFirstWindowSeconds = 10 ... For $i = 0 To $iWaitFirstWindowSeconds If WinExists($sUpdateMgTitle) Then $bAppRunning = True ExitLoop EndIf Sleep(1000) Next 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...
Spiff59 Posted July 16, 2012 Share Posted July 16, 2012 You don't need to put a WinWait() immediately before a WinWaitActive(). If you know you windows are being launched to be active the initial WinWait() is unnecessary. There are probably a million ways you can do this. Here's a differecnt approach: Func ApplyAndManagePopups () ControlClick("Properties","","[CLASS:Button; INSTANCE:4]") Local $iTimer = TimerInit(), $sWinTitle, $sOldWinTitle While 1 $sWinTitle = WinGetTitle("[active]") ; get active windows title If $sWinTitle <> $sOldWinTitle Then ; window changed $sOldWinTitle = $sWinTitle ConsoleWrite('Window: "' & $sWinTitle & '" currently active' & @CRLF) Switch $sWinTitle Case "Create Folder" ControlClick("Create Folder", "","&Yes") ConsoleWrite(' Clicking "Yes"' & @CRLF) Case "Move Folder" ControlClick("Move Folder", "","&No" & @CRLF) ConsoleWrite(' Clicking "No"') Case "Done or completed or whatever" ; whatever the final window says? Winclose($sWinTitle) ExitLoop Case Else ; handle unexpected windows? EndSwitch EndIf If TimerDiff($iTimer) > 20000 Then ; try for 20 seconds ConsoleWrite("*** Timed out ***" & @CRLF) ExitLoop EndIf Sleep(100) WEnd EndFunc Link to comment Share on other sites More sharing options...
MeepZero Posted July 16, 2012 Author Share Posted July 16, 2012 (edited) So if I'm reading your code correctly, this will check to see if the first window that pops up is the Create or Move Folder windows, and then take the appropriate action on that window. Running this on my test machine yields a result of the Move Folder window popping up, and then the console saying it is hitting "No" Problem is the dialog never actually gets to that and the "No" doesn't seem to actually be clicked. Edit: Found typo in the example, the " & @CRLF" was at the end of the controlclick statement instead of the consolewrite, retesting... Edited July 16, 2012 by MeepZero Link to comment Share on other sites More sharing options...
MeepZero Posted July 16, 2012 Author Share Posted July 16, 2012 (edited) That fixed it. With some additional tweaking I've gotten things to finally run smoothly on this! I'll start testing and cleaning up the code (like the winwait / winwait active redundancies) now and see what I can do to break it. Thanks for all the help guys. For my first time coding up some real stuff this has been a lot of fun expandcollapse popupOpt("TrayIconDebug", 1) ;Allows for debugging, YEAHHHHH!!! AutoItSetOption("WinTitleMatchMode" ,2) Func Propbox() Local $shiftab = 2 Send("{APPSKEY}r") $hWndProp = WinWait("Properties") WinWaitActive($hWndProp) Do Send("+{TAB}") ConsoleWrite("Shift Tab!" & @CRLF) $shiftab = $shiftab - 1 Until $shiftab = 0 Send("{UP}") ConsoleWrite("Up!" & @CRLF) WinWaitActive($hWndProp) Send("{TAB}") ConsoleWrite("Tab!" & @CRLF) ;Goes to the Location tab and selects the Location field, seems to not want to accept letting me reference the field in the ControlClick operation Send("H:") EndFunc Func ApplyAndManagePopups () ControlClick("Properties","","[CLASS:Button; INSTANCE:4]") Local $iTimer = TimerInit(), $sWinTitle, $sOldWinTitle While 1 $sWinTitle = WinGetTitle("[active]") ; get active windows title If $sWinTitle <> $sOldWinTitle Then ; window changed $sOldWinTitle = $sWinTitle ConsoleWrite('Window: "' & $sWinTitle & '" currently active' & @CRLF) Switch $sWinTitle Case "Create Folder" ControlClick("Create Folder", "","&Yes") ConsoleWrite(' Clicking "Yes"' & @CRLF) Case "Move Folder" ControlClick("Move Folder", "","&No") ConsoleWrite(' Clicking "No"' & @CRLF) ; Case "Done or completed or whatever" ; whatever the final window says? ; Winclose($sWinTitle) ExitLoop Case Else ; handle unexpected windows? EndSwitch EndIf If TimerDiff($iTimer) > 20000 Then ; try for 20 seconds ConsoleWrite("*** Timed out ***" & @CRLF) ExitLoop EndIf Sleep(100) WEnd EndFunc ShellExecute(@UserProfileDir) ConsoleWrite("Processing My Documents" & @CRLF) $hWndUP = WinWait(", ") WinWaitActive($hWndUP) Send("My D") Propbox() ApplyAndManagePopups() ConsoleWrite("Processing My Pictures" & @CRLF) $hWndUP = WinWait(", ") WinWaitActive($hWndUP) Send("My P") Propbox() Send("My Pictures") ApplyAndManagePopups() ConsoleWrite("Processing My Music" & @CRLF) $hWndUP = WinWait(", ") WinWaitActive($hWndUP) Send("My M") Propbox() Send("My Music") ApplyAndManagePopups() Edited July 16, 2012 by MeepZero 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