On peut faire ca assez facilement. Dans cet exemple j'ai rajouté les evenements DWebBrowserEvents2, cf MSDN, mais vous pouvez les enlever.
Code : Tout sélectionner
#include <GUIConstantsEx.au3>
#include <IE.au3>
$oIE = ObjCreate("Shell.Explorer.2")
$EventObject=ObjEvent($oIE,"IEEvent_","DWebBrowserEvents2")
if @error then
Msgbox(0,"AutoIt COM Test", _
"ObjEvent: Can't use event interface 'DWebBrowserEvents'. Error code: " & hex(@error,8))
exit
endif
$hGUI = GUICreate ("Test zazapeta", 800, 600) ;, 10, 50)
GUICtrlCreateObj($oIE, -2, -2, 800, 600)
_IENavigate($oIE, "about:blank")
$oBody = _IETagnameGetCollection($oIE, "body", 0)
_IEDocInsertHTML($oBody, "<a href=http://www.autoitscript.fr>Navigate to http://www.autoitscript.fr</a><p>")
_IEDocInsertHTML($oBody, "<BUTTON id=b1 value='Normal Exit'>Normal Exit</button> ")
_IEDocInsertHTML($oBody, "<BUTTON id=b2 value='Safe Exit'> Safe Exit </button>")
$oButton1 = _IEGetObjById($oIE, "b1")
$oButton2 = _IEGetObjById($oIE, "b2")
$oEvtButton1 = ObjEvent($oButton1, "evtButton_")
$oEvtButton2 = ObjEvent($oButton2, "evtButton_")
GUISetState()
While GUIGetMsg() <> $GUI_EVENT_CLOSE
Sleep(10)
WEnd
$EventObject.Stop ; Tell IE we don't want to receive events.
$EventObject=0 ; Kill the Event Object
exit
Func evtButton_onclick()
Local $o_object = @COM_EventObj
Switch $o_object.value
Case "Normal Exit"
Msgbox(0,"","Tu as cliqué sur le bouton Normal Exit")
Case "Safe Exit"
Msgbox(0,"","Tu as cliqué sur le bouton Safe Exit")
EndSwitch
EndFunc
Func IEEvent_BeforeNavigate2($URL, $Flags, $TargetFrameName, $PostData, $Headers, $Cancel)
; Note: the declaration is different from the one on MSDN.
ConsoleWrite( "BeforeNavigate: " & $URL & " Flags: " & $Flags & " tgframe: " & $TargetFrameName & " Postdat: " & $PostData & " Hdrs: " & $Headers & " canc: " & $Cancel & @CRLF )
EndFunc
Func IEEvent_StatusTextChange($Text)
ConsoleWrite( "IE Status text changed to: " & $Text & @CRLF )
EndFunc
Func IEEvent_PropertyChange( $szProperty)
ConsoleWrite( "IE Changed the value of the property: " & $szProperty & @CRLF )
EndFunc
Func IEEvent_DownloadComplete()
ConsoleWrite( "IE has finished a navigation operation" & @CRLF )
$oDoc= _IEDocGetObj($oIE)
ConsoleWrite( "-->Document cookie : "& $oDoc.cookie & @CRLF )
ConsoleWrite( "-->Document title : "& $oDoc.title& @CRLF )
ConsoleWrite( "-->Document referrer : "& $oDoc.referrer& @CRLF )
ConsoleWrite( "-->Document url : "& $oDoc.url& @CRLF )
EndFunc
Func IEEvent_NavigateComplete($URL)
; Note: the declaration is different from the one on MSDN.
ConsoleWrite( "IE has finished loading URL: " & $URL & @CRLF )
EndFunc
Func IEEvent_($EventName)
; This is an optional event function to catch non-defined events.
; The parameter contains the name of the event being called.
ConsoleWrite( "Uncatched event: " & $EventName & @CRLF )
EndFunc