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

    • FrancescoDiMuro
      By FrancescoDiMuro
      Good evening everyone
      Before all, I want to say that I'm doing this script to see how _IE* functions work, and see if my studs can hack a quiz I'm working on.
      I want to clarify that I'm not automating any game, bypassing any CAPTCHAs, or anything that could damage anyone.
      I was trying to autofill a form, based on which question is displayed.
      The question is always stored in here:
      <header> <h1><span class="questionid">1. </span>Here goes the question</h1> </header> And answers are stored in here:
      <ul class="answers"> <li><label><span><input id="answer_0" name="answer[]" type="radio" value="0">Answer 1</span></label></li> <li><label><span><input id="answer_1" name="answer[]" type="radio" value="1">Answer 2</span></label></li> <li><label><span><input id="answer_2" name="answer[]" type="radio" value="2">Anwser 3</span></label></li> <li><label><span><input id="answer_3" name="answer[]" type="radio" value="3">Answer 4</span></label></li> </ul></fieldset></form></div> And, there are 15 questions like this.
      How can automatically fill my form?
      Thanks in advance
      Francesco
    • Omnitica
      By Omnitica
      Hello!
      I'm new to the forums! Couldn't find any threads covering this issue. Sorry if I'm wrong.

      I'm having problems changing the text/value of a input box. The particular box doesn't have a name or id, just: class="jq_hotkeys_enabled form-control".
      This class appears multiple times throughout the source, so I don't think It's right to reference that object. 
      See image 1.
      However, I've managed to find a object with the name "ctl00$content$ctrl$ucServiceTime$rpServicetimes$ctl00$edtHiddenResourceHelper" which contains the value of the input box, and the id for the person in the dropdown/combobox left of it. (with "dummy-1" selected).
      See image 2.
      As you can see the value is 3982,4545     ( name , time )
      But when I try to change the value of it by doing:
      #include <IE.au3> Local $oIE = _IEAttach(WinGetHandle("[CLASS:IEFrame]"),"embedded") Local $oForm = _IEFormGetObjByName($oIE, "aspnetForm") Local $oInput = _IEFormElementGetObjByName($oForm, "ctl00$content$ctrl$ucServiceTime$rpServicetimes$ctl00$edtHiddenResourceHelper") _IEFormElementSetValue($oInput, "3982,1337") The box doesn't get its new value. I  can see in the source that it's changed though.
      See image 3.
       
      However, if I do: 
      #include <IE.au3> Local $oIE = _IEAttach(WinGetHandle("[CLASS:IEFrame]"),"embedded") Local $oForm = _IEFormGetObjByName($oIE, "aspnetForm") Local $oInput = _IEFormElementGetObjByName($oForm, "ctl00$content$ctrl$ucServiceTime$rpServicetimes$ctl00$edtHiddenResourceHelper") _IEFormElementSetValue($oInput, "3982,1337") $oIE.document.parentwindow.execScript("theForm.submit()") ; But it needs to reload the page The box gets its new value after the page reloads by the theForm.submit() function. 
      This is a bit unfortunate as I want the changes to happen instantly like when I type in the box with the keyboard... or select in the combobox.
      Maybe someone knows how I can do this? Looking forward to an answer! 
      Thanks in advance.
       
      Note: Unfortunately I can't provide with the real URL as it is constricted to employees in the company I work for, but let me know If I should provide anything else.
       



    • kawliga751
      By kawliga751
      I have a workplace GUI that has a search field function that pulls up customer records to allow changes. I am attempting to 1)LOGIN 2)Enter Search field, enter a number and then {ENTER} 3)change specific field once customer record loads. I have very limited experience in GUI manipulation but I am able to login using the below:
      #include <IE.au3> Const $navOpenInNewTab = 0x0800 Dim $oIE = _IECreate('http://asag.xxxxxxx.com/ASAG/index.htm') Call ("RacksheetSignIn") Func RacksheetSignIn () Local $username = _IEGetObjByName ($oIE,"uname") Local $password = _IEGetObjByName ($oIE,"pword") $oIE.Navigate2('http://asag.xxxxxxx.com/apps/RackSheets/LogInSAG/login.asp',2048) _IEFormElementSetValue ($username, "xxxxxxx") _IEFormElementSetValue ($password, "xxxxxxx") Send('{Enter}') EndFunc However I can't seem to use the _IEGetObjByName or Mouseclick to focus on the search field to allow me to enter my search criteria. When I "inspect element" in the Search field I get the attached:
       
      Any help would be MUCH appreciated
       
       
       

    • TotalAuto
      By TotalAuto
      Hi All
      I am new to AutoIT, its community, and pretty much programming in general. 
      After a bit of online research, I decided to focus on AutoIT as my first programming attempt as it seems quite powerful and amazing once you become advanced at it. I have read some introductory pdfs which where good, including from the guy I think who invented it. I also watched various sketchy youtube videos, checked out the forum etc. I have to admit it's a bit confusing starting off but I reckon if I just keep pushing forward with continual hard work I can only get better.  
      My first AutoIT project has been to open Internet Explorer and automatically log into Twitter to save doing it manually. I plan to run this after windows start up via task scheduler. I am using the #include <IE.au3> UDF but for some reason about 20% of the time I receive the following orange error notifications at the bottom of the editor (pic attached). When it happens the IE browser just doesn't open but the program continues to run which mucks up the script. 
      Does anyone know why this is happening and how it can be fixed? Also is there some other better, less error prone way, to open IE and automatically log in?
      I have tried to use the Get Object NAME and ID commands to insert the username and password (i.e. the xxxxxxxxxx's) but when I right click to use "Inspect element" there is no name or id. It seems to be some sort of java script reference?
      I am using Windows 7 with latest updates and Internet Explorer version 11.
      As this is my first post I hope I am following protocols, and if not, please let me know and I will improve.
      Thanks

    • 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.?