Jump to content



Photo

Error with embedded IE window


  • Please log in to reply
3 replies to this topic

#1 ru2cool

ru2cool

    Seeker

  • Active Members
  • 7 posts

Posted 21 February 2012 - 08:42 PM

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) -

Login Window.jpg

AutoIt         
#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("<a href='http://www.google.com' class='bbc_url' title='External link' rel='nofollow external'>http://www.google.com"</a>) $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("<a href='http://0.0.0.0/top_outbound_senders.html' class='bbc_url' title='External link' rel='nofollow external'>http://0.0.0.0/top_outbound_senders.html"</a>) ; This was a test to see if I could navigate to yahoo.com by IP address ; which does work $objIE2.Navigate("<a href='http://209.191.122.70' class='bbc_url' title='External link' rel='nofollow external'>http://209.191.122.70"</a>) 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






#2 DaleHohm

DaleHohm

    Think of IE as an API...

  • MVPs
  • 5,888 posts

Posted 22 February 2012 - 12:40 PM

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

Dale
IE.au3 issues with Vista - Workarounds, Automate input type=file (Related)SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=YFree Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curlMSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model,Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbeddedFind and harvest Enum constants for COM codeAutoIt Snippets Database - you too can contribute!Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your troubleDoesn'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?

#3 ru2cool

ru2cool

    Seeker

  • Active Members
  • 7 posts

Posted 22 February 2012 - 06:52 PM

Dale, thank you very much for the info. I will post an update once I've tested the code linked in your signature.

#4 ru2cool

ru2cool

    Seeker

  • Active Members
  • 7 posts

Posted 29 February 2012 - 06:32 PM

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?

AutoIt         
#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





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users