Jump to content
Sign in to follow this  
slbmeh

IECreatePseudoEmbedded

Recommended Posts

slbmeh

Inspired by 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

Share this post


Link to post
Share on other sites
DaleHohm

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

#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <WinAPI.au3>
#include <Constants.au3>
#include <IE.au3>

Dim $hGUI, $oIE, $sURL, $iLeft, $iTop, $iHeight, $iWidth

$sURL = "http://www.google.com"
$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
  • Like 1

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

Share this post


Link to post
Share on other sites
JohnOne

@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    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites
slbmeh

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

Share this post


Link to post
Share on other sites
wraithdu

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

Share this post


Link to post
Share on other sites
DaleHohm

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


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

Share this post


Link to post
Share on other sites
slbmeh

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

Share this post


Link to post
Share on other sites
wraithdu

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

Share this post


Link to post
Share on other sites
slbmeh

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.

Share this post


Link to post
Share on other sites
DangerousDan

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

#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
  • Like 1

Share this post


Link to post
Share on other sites
DaleHohm

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

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

Share this post


Link to post
Share on other sites
JohnOne

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

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites
DaleHohm

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


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

Share this post


Link to post
Share on other sites
DaleHohm

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

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

Share this post


Link to post
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
Sign in to follow this  

  • Similar Content

    • SkysLastChance
      By SkysLastChance
      I was wondering how I read data inside of a iframe. I would like to be able to click something inside a iframe. However, I can't even find the tag. 
      The id and name change all the time so I can't use those. 
      The code highlighted in blue is what I am trying to click. (second picture)
      Here is what I have tried.
      $target = "" $tags = $oIE.document.GetElementsByTagName("div") For $tag in $tags $class_value = $tag.GetAttribute("class") If string($class_value) = "s_92 altstyle s_93 s_94" Then $target = $tag ConsoleWrite("Tag Found " & $target.outerText&@CRLF) ExitLoop EndIf Next  

       
       

    • SkysLastChance
      By SkysLastChance
       
      WinActivate("MEDITECH - Internet Explorer") Sleep (500) $oIE = _IEAttach("MEDITECH") $oDiv1 = _IEGetObjById($oIE, "sysmenu-searchbarbutton") _IEAction($oDiv1, "click") I am just trying to click the little magnifying glass, next to the gear button with no luck. I was hoping someone might have an idea why this is not working?
       

    • SkysLastChance
      By SkysLastChance
      I am trying to type a name in patient summary search box. How should I go about doing this. I am clearly not doing it right. (Attached Picture of HTML code.)
      This is what I have tried. I assume this is not working because it is not a form? 
      WinActivate("MEDITECH - Internet Explorer")       Sleep (500)    $oIE = _IEAttach("MEDITECH")    $oForm = _IEFormGetObjByName($oIE, "systemMenu")    $oText = _IEFormElementGetObjByName($oForm, "sysmenu-searchbarinput") _IEFormElementSetValue($oText, "Hey! This works!")
    • seryth
      By seryth
      I have a script that opens some Excel books that  are stored in SharePoint .  Without getting to much into detail as its a very long story I have to open Internet Explorer to the SP site in order for all of this crap to work. 
       
      Anyway I have a bit of code in my script that i found via google-fu
      $ieList = ProcessList("iexplore.exe") If IsArray($ieList) Then For $I = 1 To Ubound($ieList) -1 ProcessWaitClose($ieList[$I][1]) Next EndIf Exit Now on Windows 7 this bit works great.  On Windows Server 2012 R2 where this things runs is another story.  I need to be able to force close all instances of Internet explorer that are running as part of my code. 
       
      Any help is appreciated. 
    • NHD
      By NHD
      Sorry, I'm not good English 

      Hi,
      I'm developing CefAu3 project, it embed Chromium browser to your AutoIt program.
      I'm busy and can stop it. If you want to contribute, you can fork my project and build it yourself.




      Some Features:
      - Easy create CEF window
      - Multi-message loop
      - Interaction between AutoIt and JavaScript
      - Supports AutoIt binding
      - Supports user events...

      Github: https://github.com/wy3/cefau3
      Wiki: https://github.com/wy3/cefau3/wiki
      CEF + UDF: https://github.com/wy3/cefau3/releases/download/releases/Cefau3.zip
      Source code: https://github.com/wy3/cefau3/archive/master.zip
       
      CEF project: https://bitbucket.org/chromiumembedded/cef
      Learn more: http://magpcss.org/ceforum/

      [Processing in CEF: 30%]
×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.