Jump to content



Photo

IECreatePseudoEmbedded

Browser IE Embedded Internet Explorer

  • Please log in to reply
15 replies to this topic

#1 slbmeh

slbmeh

    Seeker

  • Active Members
  • 12 posts

Posted 26 March 2012 - 11:51 PM

Inspired by IECreate2. I took a more simplified approach that is more reliant on IE.au3.

#include <WindowsConstants.au3> #include <WinAPI.au3> #include <Constants.au3> #include <IE.au3> Func IECreatePseudoEmbedded($iLeft, $iTop, $iWidth, $iHeight, $hParent, $sURL = "about:blank", $bShowWin = False) Local $iPID = Run(@ProgramFilesDir & "\Internet Explorer\iexplore.exe -k " & $sURL, "", @SW_HIDE) Sleep(2000) Local $oIE = _IEAttach($sURL, "URL", 1) Local $hWND = _IEPropertyGet($oIE, "hwnd") _WinAPI_SetParent($hWND, $hParent) _WinAPI_MoveWindow($hWND, $iLeft, $iTop, $iWidth, $iHeight, True) _WinAPI_SetWindowLong($hWND, $GWL_STYLE, $WS_POPUP + $WS_VISIBLE) If $bShowWin == True Then   WinSetState($hWND, "", @SW_SHOW) EndIf Return $oIE EndFunc


With this function it runs IE in kiosk mode defaulting to hidden. It will make the window a child window, resize, relocate, and redraw. It will then show the window if the ShowWin flag is set to true.

It does not handle killing the process I would like to register a cleanup function if there is a way to call a function before application close. I wan't able to find a simple way to handle this just yet, so for the time being your application should call _IEQuit on application close.

Edited by slbmeh, 26 March 2012 - 11:55 PM.








#2 DaleHohm

DaleHohm

    Think of IE as an API...

  • MVPs
  • 5,889 posts

Posted 27 March 2012 - 02:05 AM

I really like what you did. I really appreciated _IECreate2, but didn't like the process polling algorithm.

I have enhanced what you posted to further follow the IE.au3 style, made it more bullet-proof and included a working example. Haven't tested all of the failure scenarios, so your testing and that of others would be good. Nice.

Dale

AutoIt         
#include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <WinAPI.au3> #include <Constants.au3> #include <IE.au3> Dim $hGUI, $oIE, $sURL, $iLeft, $iTop, $iHeight, $iWidth $sURL = "<a href='http://www.google.com' class='bbc_url' title='External link' rel='nofollow external'>http://www.google.com"</a> $iLeft = 0 $iTop = 0 $iWidth = 1024 $iHeight = 768 $hGUI = GUICreate("Test", $iWidth, $iHeight) $oIE = IECreatePseudoEmbedded($iLeft, $iTop, $iWidth, $iHeight, $hGUI) _IENavigate($oIE, $sURL) GUISetState(@SW_SHOW, $hGUI) While 1   $msg = GUIGetMsg()   If $msg = $GUI_EVENT_CLOSE Then     _IEQuit($oIE)     Exit   EndIf WEnd Exit Func IECreatePseudoEmbedded($i_Left, $i_Top, $i_Width, $i_Height, $h_Parent, $f_ShowWin = False, $i_Timeout = 30000)    Local Const $i_Random = Random(10001, 99999, 1)    Local $i_PID, $o_IE, $h_HWND, $h_Timer = TimerInit()    $i_PID = Run(@ProgramFilesDir & "Internet Exploreriexplore.exe -k " & "about:blank-" & $i_Random, "", @SW_HIDE)    $f_ErrorNotify = _IEErrorNotify()    _IEErrorNotify(False)    While Not IsObj($o_IE)      $o_IE = _IEAttach("about:blank-" & $i_Random, "URL")      If TimerDiff($h_Timer) > $i_Timeout Then         _IEErrorNotify($f_ErrorNotify)         Return SetError(1, 0, 0)      EndIf      Sleep(200)    WEnd    _IEErrorNotify($f_ErrorNotify)    $h_HWND = _IEPropertyGet($o_IE, "hwnd")    _WinAPI_SetParent($h_HWND, $h_Parent)    _WinAPI_MoveWindow($h_HWND, $i_Left, $i_Top, $i_Width, $i_Height, True)    _WinAPI_SetWindowLong($h_HWND, $GWL_STYLE, $WS_POPUP + $WS_VISIBLE)    If $f_ShowWin Then      WinSetState($h_HWND, "", @SW_SHOW)    EndIf    Return $o_IE EndFunc   ;==>IECreatePseudoEmbedded


Notes: This modification move navigation to the URL out of the function. It creates a random URL for the initial creation so that there will be no trouble with duplicate windows. It adds a timeout waiting for the browser to be created.

Updated: Updated to use JohnOne's idle loop suggestion (below)

Edited by DaleHohm, 27 March 2012 - 02:20 PM.

  • slbmeh likes this
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 JohnOne

JohnOne

    John

  • Active Members
  • PipPipPipPipPipPip
  • 8,871 posts

Posted 27 March 2012 - 10:07 AM

@DaleHohm
As your example stands, I recieve a crash upon exiting via the gui close x

When that occurs, sometimes the spawned IE processes are not closed.
It appears to be connected to the way you have the main loop

Do     Sleep(200) Until GUIGetMsg() = $GUI_EVENT_CLOSE _IEQuit($oIE) Exit


If it is changed to

While 1     $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then   _IEQuit($oIE)   Exit EndIf WEnd


The problem is gone.

Latest release version of Autoit3
Windows 7 32
AutoIt Absolute Beginners Require a serial
Run('hh mk:@MSITStore:'&StringReplace(@AutoItExe,'.exe','.chm')&'::/html/tutorials/helloworld/helloworld.htm','',@SW_MAXIMIZE)

#4 slbmeh

slbmeh

    Seeker

  • Active Members
  • 12 posts

Posted 27 March 2012 - 12:31 PM

Notes: This modification move navigation to the URL out of the function. It creates a random URL for the initial creation so that there will be no trouble with duplicate windows. It adds a timeout waiting for the browser to be created.

I like that. Duplicate windows was a concern for me, it wouldn't affect me, because I know what could screw it up... But if others were to use it, I couldn't think of how to prevent that.

One thing I have encountered with this method is that if you use _IEPropertyGet for hwnd after you set parent it will give the parent handle and not that of the actual IE window. Do you know if there is a better way to get the handle?

I currently have this piece of code that I do not like, because I have multiple child windows and if one is open it doesn't always give expected results.

Func IEGetHandle($oIE) Local $hWND = _IEPropertyGet($oIE, "hwnd") $hWND = _WinAPI_GetWindow($hWND, $GW_CHILD) Return $hWND EndFunc


#5 wraithdu

wraithdu

    I am less fun than a twisted ankle.

  • MVPs
  • 2,137 posts

Posted 27 March 2012 - 01:55 PM

You could alter the function to return an array, with the hwnd as one of the array elements.

Edit:
Or maybe an additional byref parameter for the hwnd?

Edited by wraithdu, 27 March 2012 - 02:18 PM.


#6 DaleHohm

DaleHohm

    Think of IE as an API...

  • MVPs
  • 5,889 posts

Posted 27 March 2012 - 02:22 PM

I very rarely use the GUI functions or the WinApi functions, so I'm not much help there. I modified my post above to use JohnOne's idle loop suggestion.

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?

#7 slbmeh

slbmeh

    Seeker

  • Active Members
  • 12 posts

Posted 27 March 2012 - 02:42 PM

You could alter the function to return an array, with the hwnd as one of the array elements.

Edit:
Or maybe an additional byref parameter for the hwnd?


The array return would work, I wanted to try to remain with just the $oIE return to refrain from straying too far from the functionality of IE.au3.

I'm uncertain as to how much benefit a ByRef would be, generally the same downside as a Global with added complexity.

Edit: @JohnOne

I use GUIRegisterMsg instead of GUIGetMessage or OnEventMode, so I'm not sure why the difference there.

Edited by slbmeh, 27 March 2012 - 03:04 PM.


#8 wraithdu

wraithdu

    I am less fun than a twisted ankle.

  • MVPs
  • 2,137 posts

Posted 27 March 2012 - 05:42 PM

I'm uncertain as to how much benefit a ByRef would be, generally the same downside as a Global with added complexity.


Absolutely not. You add one byref parameter to the function call ie ByRef $hWnd, and pass in a variable of your choosing, both in name and scope. The function sets that var to the created window hwnd before changing its parent. You can do what you want with it after that. This way you can keep the same object return as the standard UDF functions.

Edited by wraithdu, 27 March 2012 - 05:43 PM.


#9 slbmeh

slbmeh

    Seeker

  • Active Members
  • 12 posts

Posted 28 March 2012 - 03:17 AM

Absolutely not. You add one byref parameter to the function call ie ByRef $hWnd, and pass in a variable of your choosing, both in name and scope. The function sets that var to the created window hwnd before changing its parent. You can do what you want with it after that. This way you can keep the same object return as the standard UDF functions.


My mention of added complexity was not of the function itself, but in applied use cases. Adding a ByRef parameter isn't difficult, but it would add a mandatory parameter that would not be necessary in many cases adding unnecessary complexity to the third party code using this function.

#10 DangerousDan

DangerousDan

    Seeker

  • Active Members
  • 44 posts

Posted 28 June 2012 - 08:40 PM

I really like what you did. I really appreciated _IECreate2, but didn't like the process polling algorithm.

I have enhanced what you posted to further follow the IE.au3 style, made it more bullet-proof and included a working example. Haven't tested all of the failure scenarios, so your testing and that of others would be good. Nice.

Dale

Dale,

You don't need to use IEAttach at all... create the object, assign it theatre mode, full screen, and hide the status bar if you need to. So far I have found that the embedded object doesn't automatically take the focus when you selet the GUI title bar, so I added an "if winactive then winactivate" line in my main program loop. I'm sure there is a better solution, but I'm still not exactly an expert with GUI's... more like a seasoned amatuer:)

Also of note: the vertical scroll bars do not redraw every time the window is resized, the GUI background color is shown until you mouseover the scroll bars or an element in the webpage that changes with the mouseover (button that emboldens, for example). I'm using _WinAPI_MoveWindow to move the embedded object when the parent moves, and have even tried manually redrawing the window after the move, hiding and unhiding it... many unconventional things as well as everything I could search for that was within my capabilities at this point, all to no avail. I worked around this by turning the scroll bars off and then back on any time the window is resized. It's a little messy visually, but it works.

I'm using autoit to scrape customer account numbers, as they are viewed by sales in our AS400, to pull up in Salesforce.com. Most of our sales people are on thin clients. I had to find a way of getting the object without using the collections method in the IEAttach function... for some reason this part of the function always gets stuck in an endless loop on our thin clients.Took me forever to figure out that was the issue, and then quite awhile to figure out a way around it. The above methods work perfectly on a PC, but my solution works in our very restrictive thin client environment and appears to be more efficient in my limited experience.

Your posts have been instrumental in my own coding, thank you for your posts and any criticism you may be wiling (anyone for that matter) to give on my code below.

Have a good day,

Dan

AutoIt         
#include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <WinAPI.au3> #include <Constants.au3> #include <IE.au3> Func IECreatePseudoEmbedded($i_Left, $i_Top, $i_Width, $i_Height, $h_Parent) Local $o_IE, $h_HWND $o_IE = ObjCreate("InternetExplorer.Application") $o_IE.theatermode = True $o_IE.fullscreen = True $o_IE.statusbar = False $h_HWND = _IEPropertyGet($o_IE, "hwnd") _WinAPI_SetParent($h_HWND, $h_Parent) _WinAPI_MoveWindow($h_HWND, $i_Left, $i_Top, $i_Width, $i_Height, False) _WinAPI_SetWindowLong($h_HWND, $GWL_STYLE, $WS_POPUP + $WS_VISIBLE) Return $o_IE EndFunc ;==>IECreatePseudoEmbedded

  • syk3s likes this

#11 JohnOne

JohnOne

    John

  • Active Members
  • PipPipPipPipPipPip
  • 8,871 posts

Posted 15 April 2013 - 04:42 AM

I'm a great fan of these methods, but alas with IE.10 It crashes upon exit if there is another instance of IE open besides itself.

I'd be happy to hear is anyone has a solution to this.
AutoIt Absolute Beginners Require a serial
Run('hh mk:@MSITStore:'&StringReplace(@AutoItExe,'.exe','.chm')&'::/html/tutorials/helloworld/helloworld.htm','',@SW_MAXIMIZE)

#12 DaleHohm

DaleHohm

    Think of IE as an API...

  • MVPs
  • 5,889 posts

Posted 15 April 2013 - 01:27 PM

Can you be more specific, please? What crashes, when what exits? Error messages?

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?

#13 JohnOne

JohnOne

    John

  • Active Members
  • PipPipPipPipPipPip
  • 8,871 posts

Posted 15 April 2013 - 02:20 PM

Sorry, Internet explorer crashes., with the usual box...

"Internet explorer has stopped working"
"check online"
"Restart" or sometimes "close"
"debug"

Problem signature:
Problem Event Name: APPCRASH
Application Name: iexplore.exe
Application Version: 10.0.9200.16537
Application Timestamp: 512347f7
Fault Module Name: IEFRAME.dll
Fault Module Version: 10.0.9200.16540
Fault Module Timestamp: 5125f35b
Exception Code: c0000005
Exception Offset: 000163e2
OS Version: 6.1.7601.2.1.0.256.48
Locale ID: 2057
Additional Information 1: 0a9e
Additional Information 2: 0a9e372d3b4ad19135b953a78882e789
Additional Information 3: 0a9e
Additional Information 4: 0a9e372d3b4ad19135b953a78882e789


Crashes however you end it, even with ctrl + Break

Edited by JohnOne, 15 April 2013 - 02:21 PM.

AutoIt Absolute Beginners Require a serial
Run('hh mk:@MSITStore:'&StringReplace(@AutoItExe,'.exe','.chm')&'::/html/tutorials/helloworld/helloworld.htm','',@SW_MAXIMIZE)

#14 DaleHohm

DaleHohm

    Think of IE as an API...

  • MVPs
  • 5,889 posts

Posted 15 April 2013 - 06:42 PM

Odd. When I run DangerousDan's version of the code, I get no crash (running the same version of 32-bit IE10 as you are).

Perhaps you can post a reproducer or try on another machine running IE10.

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?

#15 JohnOne

JohnOne

    John

  • Active Members
  • PipPipPipPipPipPip
  • 8,871 posts

Posted 15 April 2013 - 09:02 PM

I will try when I have access to another PC tomorrow.

You ran it with another instance of IE10 open?
AutoIt Absolute Beginners Require a serial
Run('hh mk:@MSITStore:'&StringReplace(@AutoItExe,'.exe','.chm')&'::/html/tutorials/helloworld/helloworld.htm','',@SW_MAXIMIZE)

#16 DaleHohm

DaleHohm

    Think of IE as an API...

  • MVPs
  • 5,889 posts

Posted 16 April 2013 - 01:02 PM

Yes, I did. The one from whence I am replying to you.

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?





Also tagged with one or more of these keywords: Browser, IE, Embedded, Internet Explorer

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users