Sign in to follow this  
Followers 0
slbmeh

IECreatePseudoEmbedded

16 posts in this topic

#1 ·  Posted (edited)

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



#2 ·  Posted (edited)

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
1 person likes this

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

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

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

#5 ·  Posted (edited)

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

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

#7 ·  Posted (edited)

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

#8 ·  Posted (edited)

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

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

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
1 person likes this

Share this post


Link to post
Share on other sites

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

#13 ·  Posted (edited)

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

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

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  
Followers 0

  • Similar Content

    • ur
      By ur
      For the below form, I am able to automate using below code for textboxes.

      #include <IE.au3> Local $oIE = _IEAttach("http://localhost:18170/MartAdmin/", "url") _IELoadWait($oIE) $Search = _IEGetObjById($oIE,"x-auto-16-input") _IEPropertySet($Search, 'innerText','Uday KIran') $Search = _IEGetObjById($oIE,"x-auto-18-input") _IEPropertySet($Search, 'innerText','Uday KIran') But for the Login button, there is no id or name.
      The html code when I click on Inspect element in browser, shown below.
      <button tabindex="0" class="x-btn-text" style="width: 64px; position: relative;" type="button">Log In</button> Please let me know how to click this.?
       
    • whiskas
      By whiskas
      Hi all,
      I just upgraded to windows 10 and am using Edge as my browser now. Updated my scripts, but I can not unhide a minimized Edge window with the script anymore.
      WinSetState ( "titlle","", @SW_MAXIMIZE ) works fine, but not if it is minimized. Tried same with SW_SHOW, doesn't work.
      WinExists("title","") -> returns 1, so it is finding my window.
       
              WinWait($title,$text,$timeout)
              If Not WinActive($title,$text) Then WinActivate($title,$text)
              WinWaitActive($title,$text,$timeout)
      Doesn't work also, so I think I tried all but cant get the window back
      Any help would be appreciated
       
    • Arlen
      By Arlen
      I'm doing a script to login and check my grades for college and some other useful things. But how can I check if i'm already logged in.
      What I have tried is to _IEDocReadHTML and then try to read the string with my username or anything that indicates I am logged. But it never returns the actually real html that I am seeing on my browser. It only returned a logged out html version. Anyway I can find out when I am logged or not. Thanks.
    • jonson1986
      By jonson1986
      Hey,
      I'm trying to select language from drop-down menu on a webpage by _IEGetObjById but it's  not working, It mean autoit open the page but unable to select my desired value not even by matching text or by value, I'm looking for kind help...I've pastes my Autoit codes below along with source codes(using ie) of the webpage ;
      #include <IE.au3> $site = "http://example.com/upload" $oIE = _IECreate($site) $oDownloadSamples = _IEGetObjById($oIE, "language") $oDownloadSamplesSelect = _IETagNameGetCollection($oDownloadSamples, "select", "language") $oDownloadSamplesSelect.focus _IEFormElementOptionSelect($oDownloadSamplesSelect, "French", 1, "byText") Sleep (1000) _IEFormElementOptionSelect($oDownloadSamplesSelect, "2", 1, "byValue") HTML Codes using IE:
      <html> <head> <div class="form-row"> <div class="col-7"> <label>Language</label> <select name="language" class="select" id="language"> <option value="1">English</option> <option value="2">French</option> <option value="3">German</option> <option value="4">Italian</option> <option value="5">Japanese</option> <option value="6">Spanish</option> <option value="7">Russian</option> <option value="8">Hindi</option> <option value="9">Arabic</option> <option value="10">Chinese</option> <option value="11">Dutch</option> <option value="12">Finnish</option> <option value="13">Korean</option> <option value="14">Norwegian</option> <option value="15">Portuguese</option> <option value="16">Romanian</option> <option value="17">Serbian</option> <option value="18">Croatian</option> <option value="20">Polish</option> <option value="21">Afar</option> <option value="22">Abkhazian</option> <option value="23">Afrikaans</option> <option value="24">Amharic</option> <option value="25">Assamese</option> <option value="26">Aymara</option> <option value="27">Azerbaijani</option> <option value="28">Bashkir</option> <option value="29">Belarusian</option> <option value="30">Bulgarian</option> <option value="31">Bihari</option> <option value="32">Bislama</option> <option value="33">Bengali/Bangla</option> <option value="34">Tibetan</option> <option value="35">Breton</option> <option value="36">Catalan</option> <option value="37">Corsican</option> <option value="38">Czech</option> <option value="39">Welsh</option> <option value="40">Danish</option> <option value="41">Bhutani</option> <option value="42">Greek</option> <option value="43">Esperanto</option> <option value="44">Estonian</option> <option value="45">Basque</option> <option value="46">Persian</option> <option value="47">Fiji</option> <option value="48">Faeroese</option> <option value="49">Frisian</option> <option value="50">Irish</option> <option value="51">Scots/Gaelic</option> <option value="52">Galician</option> <option value="53">Guarani</option> <option value="54">Gujarati</option> <option value="55">Hausa</option> <option value="56">Hungarian</option> <option value="57">Armenian</option> <option value="58">Interlingua</option> <option value="59">Interlingue</option> <option value="60">Inupiak</option> <option value="61">Indonesian</option> <option value="62">Icelandic</option> <option value="63">Hebrew</option> <option value="64">Yiddish</option> <option value="65">Javanese</option> <option value="66">Georgian</option> <option value="67">Kazakh</option> <option value="68">Greenlandic</option> <option value="69">Cambodian</option> <option value="70">Kannada</option> <option value="71">Kashmiri</option> <option value="72">Kurdish</option> <option value="73">Kirghiz</option> <option value="74">Latin</option> <option value="75">Lingala</option> <option value="76">Laothian</option> <option value="77">Lithuanian</option> <option value="78">Latvian/Lettish</option> <option value="79">Malagasy</option> <option value="80">Maori</option> <option value="81">Macedonian</option> <option value="82">Malayalam</option> <option value="83">Mongolian</option> <option value="84">Moldavian</option> <option value="85">Marathi</option> <option value="86">Malay</option> <option value="87">Maltese</option> <option value="88">Burmese</option> <option value="89">Nauru</option> <option value="90">Nepali</option> <option value="91">Occitan</option> <option value="92">(Afan)/Oromoor/Oriya</option> <option value="93">Punjabi</option> <option value="94">Pashto/Pushto</option> <option value="95">Quechua</option> <option value="96">Rhaeto-Romance</option> <option value="97">Kirundi</option> <option value="98">Kinyarwanda</option> <option value="99">Sanskrit</option> <option value="100">Sindhi</option> <option value="101">Sangro</option> <option value="102">Serbo-Croatian</option> <option value="103">Singhalese</option> <option value="104">Slovak</option> <option value="105">Slovenian</option> <option value="106">Samoan</option> <option value="107">Shona</option> <option value="108">Somali</option> <option value="109">Albanian</option> <option value="110">Siswati</option> <option value="111">Sesotho</option> <option value="112">Sundanese</option> <option value="113">Swedish</option> <option value="114">Swahili</option> <option value="115">Tamil</option> <option value="116">Telugu</option> <option value="117">Tajik</option> <option value="118">Thai</option> <option value="119">Tigrinya</option> <option value="120">Turkmen</option> <option value="121">Tagalog</option> <option value="122">Setswana</option> <option value="123">Tonga</option> <option value="124">Turkish</option> <option value="125">Tsonga</option> <option value="126">Tatar</option> <option value="127">Twi</option> <option value="128">Ukrainian</option> <option value="129">Urdu</option> <option value="130">Uzbek</option> <option value="131">Vietnamese</option> <option value="132">Volapuk</option> <option value="133">Wolof</option> <option value="134">Xhosa</option> <option value="135">Yoruba</option> <option value="136">Zulu</option> <option value="19">Other</option> </select> </div> </main> </body> </html>