melkortheevil Posted December 15, 2009 Posted December 15, 2009 (edited) Hi, the example code below opens IE window on button click. I am trying to close the IE window on second click and break the running function. I am asking for help with the following issues: 1. If you don't wait long enough to see autoit web site loaded there is an error message in AutoIt cosole and the script will exit. I guess that's because $oIE doen't exist anymore. IE.au3 (586) : ==> Variable must be of type "Object". 2. If you wait long enough you can close IE but the function is still running as you can see in console. Is there a way to break the running function? expandcollapse popup#include <IE.au3> #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> Global $oIE, $oHWND Global $Form1, $Button1 Opt("GUIOnEventMode", 1) $Form1 = GUICreate("Meteor SMS Agent v0.2", 304, 329, 246, 160) GUISetOnEvent($GUI_EVENT_CLOSE, "Quit") $Button1 = GUICtrlCreateButton("Run IE", 48, 224, 83, 33) GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif") GUICtrlSetOnEvent(-1, "smssendbutton") GUISetState() $running = True $startsmssend = False While 1 Sleep(100) If $startsmssend Then smssend() $startsmssend = False EndIf WEnd Func smssendbutton() $sButtonText = GUICtrlRead ($Button1) If $sButtonText = "Run IE" Then ; Change the text on Button on click GUICtrlSetData($Button1, "STOP IE") Else GUICtrlSetData($Button1, "Run IE") EndIf $running = Not $running ;$running is False on first click If ($running = True) And ($startsmssend = True) Then _Quit() If $startsmssend = False then $startsmssend = True EndFunc ;==>smssendbutton Func smssend() ;THIS IS THE MAIN FUNCTION $oIE = _IECreate () ;$oIE = _IECreate ("https://www.mymeteor.ie/go/login") ;it's still loading, can't terminate it $oHWND = _IEPropertyGet($oIE, "hwnd") _IENavigate($oIE, "https://www.mymeteor.ie/go/login") _IENavigate($oIE, "http://www.autoitscript.com") For $ir = 0 To 1000 Sleep(50) ConsoleWrite($ir & @CRLF) Sleep(50) Next EndFunc Func _Quit() _IEQuit ($oIE) ;first try $oIE=0 ;_IEAction ( $oIE, "quit") ; second try ;If WinExists($oHWND) then $oIE.Quit ; third try ConsoleWrite ( "Done" ) EndFunc Func Quit() Exit EndFunc Edited December 15, 2009 by melkortheevil
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