Lanturn Posted March 1, 2005 Share Posted March 1, 2005 Assuming I have the following script to check if a IE browser window is loaded... If I click the button to open a new browser window and try the close the GUI before the new browser window becomes active... it would fail... Any method around this? expandcollapse popup#cs Browser Page Loaded Checker =========================== Checks if a browser window has finished loading. IE Only. #ce #include <GuiConstants.au3> $lastWin = WinGetTitle("") GUICreate("Browser Page Loaded Checker", 400, 150, 0, 0, -1, $WS_EX_TOPMOST) GUICtrlCreateLabel("Currently Active Window:", 10, 30, 120) GUICtrlCreateLabel("Last Active Window:", 10, 60, 120) $CurrID = GUICtrlCreateLabel("<Currently Active Window>", 150, 30, 220, 30) $LastID = GUICtrlCreateLabel("<Last Active Window>", 150, 60, 220, 30) $HintID = GUICtrlCreateLabel("Select the browser window as the active window to verify...", 10, 90, 380) $BttnID = GUICtrlCreateButton("www.google.com", 10, 120, 100) GUISetState(); $nowWin = WinGetTitle("") GUICtrlSetData($CurrID, $nowWin) GUICtrlSetData($LastID, $lastWin) While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $BttnID Run(@ProgramFilesDir & "\Internet Explorer\iexplore.exe www.google.com") setHint("Opening www.google.com") WinWaitActive("Microsoft Internet Explorer") EndSelect If WinGetTitle("") <> $nowWin Then $lastWin = $nowWin $nowWin = WinGetTitle("") GUICtrlSetData($CurrID, $nowWin) GUICtrlSetData($LastID, $lastWin) EndIf If StringInStr($nowWin, "Microsoft Internet Explorer") <> 0 Then If StatusbarGetText($nowWin) = "Done" Then setHint("The page is loaded!!") MsgBox(64, "Success", "Page is loaded!") ExitLoop Else setHint("The page isn't loaded yet...") EndIf Else setHint("Set an 'Internet Explorer' browser window as the active window...") EndIf WEnd Func setHint($msg) If GUICtrlRead($HintID) <> $msg Then GUICtrlSetData($HintID, $msg) EndFunc ;==>setHint Link to comment Share on other sites More sharing options...
zcoacoaz Posted March 1, 2005 Share Posted March 1, 2005 use OnEvent mode like this expandcollapse popup#cs Browser Page Loaded Checker =========================== Checks if a browser window has finished loading. IE Only. #ce #include <GuiConstants.au3> AutoItSetOption ( "GUIOnEventMode", 1 ) $lastWin = WinGetTitle("") GUICreate("Browser Page Loaded Checker", 400, 150, 0, 0, -1, $WS_EX_TOPMOST) GUISetOnEvent ( $GUI_EVENT_CLOSE, "Quit" ) GUICtrlCreateLabel("Currently Active Window:", 10, 30, 120) GUICtrlCreateLabel("Last Active Window:", 10, 60, 120) $CurrID = GUICtrlCreateLabel("<Currently Active Window>", 150, 30, 220, 30) $LastID = GUICtrlCreateLabel("<Last Active Window>", 150, 60, 220, 30) $HintID = GUICtrlCreateLabel("Select the browser window as the active window to verify...", 10, 90, 380) $BttnID = GUICtrlCreateButton("www.google.com", 10, 120, 100) GuiCtrlSetOnEvent ( $BttnID, "BttnID_Pressed" ) GUISetState(); $nowWin = WinGetTitle("") GUICtrlSetData($CurrID, $nowWin) GUICtrlSetData($LastID, $lastWin) While 1 If WinGetTitle("") <> $nowWin Then $lastWin = $nowWin $nowWin = WinGetTitle("") GUICtrlSetData($CurrID, $nowWin) GUICtrlSetData($LastID, $lastWin) EndIf If StringInStr($nowWin, "Microsoft Internet Explorer") <> 0 Then If StatusbarGetText($nowWin) = "Done" Then setHint("The page is loaded!!") MsgBox(64, "Success", "Page is loaded!") ExitLoop Else setHint("The page isn't loaded yet...") EndIf Else setHint("Set an 'Internet Explorer' browser window as the active window...") EndIf WEnd Func setHint($msg) If GUICtrlRead($HintID) <> $msg Then GUICtrlSetData($HintID, $msg) EndFunc ;==>setHint Func Quit() Exit EndFunc Func ButtID_Pressed() Run(@ProgramFilesDir & "\Internet Explorer\iexplore.exe www.google.com") setHint("Opening www.google.com") WinWaitActive("Microsoft Internet Explorer") EndFunc [font="Times"] If anyone remembers me, I am back. Maybe to stay, maybe not.----------------------------------------------------------------------------------------------------------[/font][font="Times"]Things I am proud of: Pong! in AutoIt | SearchbarMy website: F.R.I.E.S.A little website that is trying to get started: http://thepiratelounge.net/ (not mine)[/font][font="Times"] ----------------------------------------------------------------------------------------------------------[/font][font="Arial"]The newbies need to stop stealing avatars!!! It is confusing!![/font] Link to comment Share on other sites More sharing options...
Lanturn Posted March 1, 2005 Author Share Posted March 1, 2005 Wouldn't WinWaitActive pause execution of the script until the window is active? Or would events still take place? Matt 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