Jump to content

Error with embedded IE window


ru2cool
 Share

Recommended Posts

I am attempting to design a GUI with two embedded IE windows for a project at work and need help with an unexpected error. The issue I've encountered is that one of the URLs will not load. The site in question is a network server which requires authentication prior to loading the page. I am able to get the login prompt to launch if I navigate to the site using the 'InternetExplorer.Application' object. However, my GUI window simply says 'Navigation to the webpage was canceled' if I try to navigate there using the 'Shell.Application.2' object.

Ideally, I would like the login prompt to launch first so the user can authenticate. I've written in a loop to delay the GUI from being displayed until both web pages have loaded. But, that does no good if navigation for the second page is canceled.

If anyone knows a workaround for this issue I would be most grateful. Below is a screenshot of the login window & my code (I had to censor the IP address & server name due to our security policies at work) -

post-69755-0-75797900-1329856721_thumb.j

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Opt("MustDeclareVars", 1)

#region ========================= SPECIAL USE VARIABLES =========================
; INTEGERS for counters, loops, switch based logic, and function calls
Local $l = 0

; STRINGS for counters, loops, & logical statements
Local $w
#endregion ======================================================================

; Control ID variables
Local $Form1, $Obj1, $Obj2

; Object variables
Local $objIE1, $objIE2


$Form1 = GUICreate("Embedded Web Pages", 1001, 751, 200 , 50)
$objIE1 = ObjCreate("Shell.Explorer.2")
$Obj1 = GUICtrlCreateObj($objIE1, 0, 0, 1000, 375)

; I used google.com as an example only.  The work related URL
; loads ok for the first embedded page.
$objIE1.Navigate("http://www.google.com")

$objIE2 = ObjCreate("Shell.Explorer.2")
$Obj2 = GUICtrlCreateObj($objIE2, 0, 375, 1000, 375)

; Below is the URL I'm trying to use for work (IP address censored)
; $objIE2.Navigate("http://0.0.0.0/top_outbound_senders.html")

; This was a test to see if I could navigate to yahoo.com by IP address
; which does work
$objIE2.Navigate("http://209.191.122.70")

Do

Select

  Case $objIE1.Busy

  Case $objIE2.Busy

  Case Else

   $l = 1

EndSelect

Until $l = 1

GUISetState(@SW_SHOW)

While 1

Switch GUIGetMsg()

  Case $GUI_EVENT_CLOSE

   Exit

EndSwitch

WEnd
Link to comment
Share on other sites

See my sig for an interesting approach as an alrternative to _IECreateEmbedded

Dale

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

My apologies for the delayed response, but after much testing I've been able to embed an IE window into my form & set up basic browsing controls. The program will store up to 20 URLs before it starts removing the first entry when a new URL is added. The code is a bit lengthy but I wanted to share it with the community in case someone else may have a similar need.

Thank you again Dale for the most excellent assist. If I may ask, how do I edit the title of this topic to include the [sOLVED] prefix?

#include <ButtonConstants.au3>
#Include <Constants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WinAPI.au3>
#Include <WindowsConstants.au3>

Local $Form1, $Border1, $Border2, $Label1, $Input1
Local $Button1, $Button2, $Button3

Local $arrURLs, $strURLs = "", $Counter = 1, $Switch = 0, $objIE, $objIEdoc

_EmbedIE()

Func _EmbedIE()

    $Form1 = GUICreate("Test", 1000, 750, 200, 50, BitOR($WS_CAPTION, $WS_SYSMENU, $WS_CLIPCHILDREN))
    $Border1 = GUICtrlCreateLabel("", 0, 30, 1000, 720, $SS_SUNKEN)
    $Button1 = GUICtrlCreateButton("Back", 5, 5, 55, 20)
    $Button2 = GUICtrlCreateButton("Forward", 65, 5, 55, 20)
    $Button3 = GUICtrlCreateButton("GO", 665, 5, 30, 20)
    GUICtrlSetState($Button1, $GUI_DISABLE)
    GUICtrlSetState($Button2, $GUI_DISABLE)
    $Label1 = GUICtrlCreateLabel("URL", 125, 5, 26, 20, BitOR($SS_CENTER, $SS_CENTERIMAGE))
    $Input1 = GUICtrlCreateInput("", 155, 5, 500, 20)

    $processID = Run(@ProgramFilesDir & "\internet explorer\iexplore.exe -k" , "", @SW_HIDE)
    ProcessWait($processID)
    Sleep(500)
    $objIE = _GetIEObject($processID)
    ObjEvent($objIE, "_IEEvent_", "DWebBrowserEvents2")
    $objIE.Navigate("about:blank")

    Do

        $objIEdoc = $objIE.Document

    Until IsObj($objIEdoc)

    ObjEvent($objIEdoc, "_IEDocEvent_")
    $hwndIE = HWnd($objIE.HWND)
    _WinAPI_SetParent($hwndIE, $Form1)
    _WinAPI_MoveWindow($hwndIE, 1, 31, 998, 718, True)
    _WinAPI_SetWindowLong($hwndIE, $GWL_STYLE, BitOR($WS_CHILD, $WS_VISIBLE))

    GUISetState(@SW_SHOW)

EndFunc

Func _PageCounter()

    If $Switch < 1 Or $Switch > 2 Then

        $arrURLs = StringSplit($strURLs, ",")

        If $arrURLs[0] > 20 Then

            $strURLs = StringMid($strURLs, StringInStr($strURLs, ",") + 1)
            $arrURLs = StringSplit($strURLs, ",")

        EndIf

        If $Counter < 20 And $Switch > 2 Then

            $Counter += 1

        EndIf

    EndIf

    Switch $Switch

        Case 1

            If $Counter < 2 Then

                GUICtrlSetState($Button1, $GUI_DISABLE)

            EndIf

            GUICtrlSetState($Button2, $GUI_ENABLE)

        Case 2

            If $Counter >= $arrURLs[0] Then

                GUICtrlSetState($Button2, $GUI_DISABLE)

            EndIf

            GUICtrlSetState($Button1, $GUI_ENABLE)

        Case 3 To 4

            If $Counter > 1 Then

                GUICtrlSetState($Button1, $GUI_ENABLE)

            EndIf

            GUICtrlSetState($Button2, $GUI_DISABLE)

    EndSwitch

EndFunc

Func _GetIEObject($pid)

    $objShell = ObjCreate("Shell.Application")
    $objShellWindows = $objShell.Windows

    If $objShellWindows.Count > 0 Then

        For $objShellWindow In $objShellWindows

            If WinGetProcess(HWnd($objShellWindow.HWND)) = $pid Then

                Return $objShellWindow

            EndIf

        Next

    EndIf

EndFunc

Func _PostNavigation()

    While $objIE.Busy

        Sleep(100)

    WEnd

    GUICtrlSetData($Input1, $objIE.LocationURL)

EndFunc

Func _IEDocEvent_OnClick()

    $Switch = 4

EndFunc

Func _IEEvent_BeforeNavigate2($IEobj, $IEurl, $Flags, $TargetFrameName, $PostData, $Headers, $Cancel)

    If $IEobj = $objIE Then

        GUICtrlSetData($Input1, $IEurl)

    EndIf

EndFunc

Func _IEEvent_NavigateComplete2($IEobj, $IEurl)

    If $IEobj = $objIE Then

        If $Switch = 0 Then

            $a = StringInStr($strURLs, ",", 0, -1)
            $strURLs = StringMid($strURLs, 1, $a) & $IEurl
            _PageCounter()

        Else

            If $strURLs = "" Then

                $strURLs = $IEurl
                _PageCounter()

            Else

                If StringInStr($strURLs, $IEurl) = 0 Then

                    $strURLs &= "," & $IEurl
                    _PageCounter()

                ElseIf $arrURLs[$arrURLs[0]] <> $IEurl Then

                    For $a = 1 to $Counter - 1

                        Select

                            Case $a = 1

                                $strURLs = $arrURLs[$a]

                            Case Else

                                $strURLs &= "," & $arrURLs[$a]

                        EndSelect

                    Next

                    $strURLs &= "," & $IEurl
                    _PageCounter()

                EndIf

            EndIf

            $Switch = 0

        EndIf

        _PostNavigation()

    EndIf

EndFunc

While 1

    Switch GUIGetMsg()

        Case $GUI_EVENT_CLOSE

            GUISetState(@SW_HIDE)
            $objIE.Quit
            Sleep(500)
            Exit

        Case $Button1

            $Switch = 1
            $Counter -= 1
            _PageCounter()
            $objIE.Navigate($arrURLs[$Counter])

        Case $Button2

            $Switch = 2
            $Counter += 1
            _PageCounter()
            $objIE.Navigate($arrURLs[$Counter])

        Case $Button3

            $URL = GUICtrlRead($Input1)

            If $URL = "" Then

                $URL = "about:blank"

            EndIf

            $Switch = 3
            $objIE.Navigate($URL)

        Case $Input1

            ControlClick($Form1, "", $Button3)

    EndSwitch

WEnd
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...