Create a Webbrowser object suitable for embedding in an AutoIt GUI with GUICtrlCreateObj()
#include <IE.au3>
_IECreateEmbedded ( )
Success: | a Webbrowser object reference. |
Failure: | sets the @error flag to non-zero. |
@error: | 1 ($_IEStatus_GeneralError) - General Error |
No actions can be performed on this object until it has been embedded into a parent application (e.g. you cannot perform an _IENavigate().
Because of this restriction, the browser is not automatically navigated to 'about:blank' as is a browser created with _IECreate().
You must therefore use _IENavigate() to navigate this browser to 'about:blank' after it has been embedded into the parent application and before you attempt any operations that rely on having a document loaded (e.g. _IEBodyWriteHTML()
).
There are several properties related to an InternetExplorer object (e.g. returned by _IECreate() ) that do not apply to this object.
These include status text, addressbar and others that may exist for a browser, but do not exist for an embedded control.
You may have object visibility issues unless you use the Windows style $WS_CLIPCHILDREN in GUICreate().
_IEQuit() cannot be used with this object. The object will be destroyed when its parent GUI is destroyed.
_IEAttach, _IECreate, _IENavigate
; Trap COM errors so that 'Back' and 'Forward'
; outside of history bounds does not abort script
; (expect COM errors to be sent to the console)
#include <GUIConstantsEx.au3>
#include <IE.au3>
#include <WindowsConstants.au3>
Local $oIE = _IECreateEmbedded()
GUICreate("Embedded Web control Test", 640, 580, _
(@DesktopWidth - 640) / 2, (@DesktopHeight - 580) / 2, _
$WS_OVERLAPPEDWINDOW + $WS_CLIPSIBLINGS + $WS_CLIPCHILDREN)
GUICtrlCreateObj($oIE, 10, 40, 600, 360)
Local $idButton_Back = GUICtrlCreateButton("Back", 10, 420, 100, 30)
Local $idButton_Forward = GUICtrlCreateButton("Forward", 120, 420, 100, 30)
Local $idButton_Home = GUICtrlCreateButton("Home", 230, 420, 100, 30)
Local $idButton_Stop = GUICtrlCreateButton("Stop", 340, 420, 100, 30)
Global $g_idError_Message = GUICtrlCreateLabel("", 100, 500, 500, 30)
GUICtrlSetColor(-1, 0xff0000)
GUISetState(@SW_SHOW) ;Show GUI
_IENavigate($oIE, "http://www.autoitscript.com")
_IEAction($oIE, "stop")
; Waiting for user to close the window
While 1
Local $iMsg = GUIGetMsg()
Select
Case $iMsg = $GUI_EVENT_CLOSE
ExitLoop
Case $iMsg = $idButton_Home
_IENavigate($oIE, "http://www.autoitscript.com")
_IEAction($oIE, "stop")
_IEAction($oIE, "back")
CheckError("Home", @error, @extended)
Case $iMsg = $idButton_Back
_IEAction($oIE, "back")
CheckError("Back", @error, @extended)
Case $iMsg = $idButton_Forward
_IEAction($oIE, "forward")
CheckError("Forward", @error, @extended)
Case $iMsg = $idButton_Stop
_IEAction($oIE, "stop")
CheckError("Stop", @error, @extended)
EndSelect
WEnd
GUIDelete()
Exit
Func CheckError($sMsg, $iError, $iExtended)
If $iError Then
$sMsg = "Error using " & $sMsg & " button (" & $iExtended & ")"
Else
$sMsg = ""
EndIf
GUICtrlSetData($g_idError_Message, $sMsg)
EndFunc ;==>CheckError