Jump to content

Get/Store Multiple IE Objs


Recommended Posts

I'm not sure what's going on with $oIE returned from _IECreate() in that when I ConsoleWrite() it doesn't show what it is. I understand that it is returning the handler (or something), but how do I store this in like an array?

The reason is that I have a GUI that can open multiple IE Objs using Dale's IE.au3 UDF, but on exit of the script/gui I want the opened IE Objs to quit using IEQuit().

I hope this makes sense!

A decision is a powerful thing
Link to comment
Share on other sites

Makes perfect sense, actually, and I believe it's possible, I just don't store the objects for use later in the program. I use _IECreate() for the windows, grab the window handle, and then re-attach later on to the specific IE window I want later on with _IEAttach($hwnd, "HWND"). That makes it much less prone to errors.

<...>

$oIE_CRU = _IECreate("http://some.address.com", 0, 1, 1, 0)
$hwndCRU = WinGetHandle("Website Title", "")
$oIE_RTB = _IECreate("http://some.othersite.com", 0, 1, 1, 0)
$hwndRTB = WinGetHandle("Another Title", "")

<...>

$oIE_CRU = _IEAttach($hwndCRU, "HWND") ; attach to the IE process
If @error Then
     DBP('Unable to attach to IE Window CRU', 5000, 1)
     Exit 5000
EndIf
$oCRUForm = _IEFormGetObjByName($oIE_CRU, "FSUForm") ; attach to the form inside the window

and so on.

This is just a snippet from a 2100 line (and growing) program that I use at work to manipulate 3 different IE sessions, 4 AS-400 emulators, and two in-house VB programs. >.<

I really need to de-spaghettify it.

Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

Link to comment
Share on other sites

Makes perfect sense, actually, and I believe it's possible, I just don't store the objects for use later in the program. I use _IECreate() for the windows, grab the window handle, and then re-attach later on to the specific IE window I want later on with _IEAttach($hwnd, "HWND"). That makes it much less prone to errors.

<...>

$oIE_CRU = _IECreate("http://some.address.com", 0, 1, 1, 0)
$hwndCRU = WinGetHandle("Website Title", "")
$oIE_RTB = _IECreate("http://some.othersite.com", 0, 1, 1, 0)
$hwndRTB = WinGetHandle("Another Title", "")

<...>

$oIE_CRU = _IEAttach($hwndCRU, "HWND") ; attach to the IE process
If @error Then
     DBP('Unable to attach to IE Window CRU', 5000, 1)
     Exit 5000
EndIf
$oCRUForm = _IEFormGetObjByName($oIE_CRU, "FSUForm") ; attach to the form inside the window

and so on.

This is just a snippet from a 2100 line (and growing) program that I use at work to manipulate 3 different IE sessions, 4 AS-400 emulators, and two in-house VB programs. >.<

I really need to de-spaghettify it.

Awesome! Thank you. I didn't even consider doing it that way with the WinGetHandle(). Furthermore I like what you've done with the IEAttach! That's a good idea too.

Thanks Blue_Darche! again

A decision is a powerful thing
Link to comment
Share on other sites

Yeah. The nice part about using handles is ... the title can change all day long, but you'll still snag the same window as before. As long as the window doesn't close...

Well, thank you! With these two ideas as a part of my arsenal, I'll get some fine things knocked down :)

A decision is a powerful thing
Link to comment
Share on other sites

You can save and use the Object Handles returned by _IECreate etc. -- you just cannot expect to display the contents of an Object Handle to the console and expect that it is readable content.

The window handle idea is a good one -- just be aware that with a tabbed browser, the window handle represents the overall browser containing, perhaps, multiple browser instances and closing that window closes them all. The Object hangles allow you to manage them independantly.

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

Link to comment
Share on other sites

You can save and use the Object Handles returned by _IECreate etc. -- you just cannot expect to display the contents of an Object Handle to the console and expect that it is readable content.

The window handle idea is a good one -- just be aware that with a tabbed browser, the window handle represents the overall browser containing, perhaps, multiple browser instances and closing that window closes them all. The Object hangles allow you to manage them independantly.

Dale

Dale THANKS that rad!!! It works!!!! That's exactly what I'm LOOKING FOR!!!! ;):)

#include <IE.au3>

Local $ieObjArray[2]
$ieObjArray[0] = _IECreate("http:\\www.google.com",0,1)
$ieObjArray[1] = _IECreate("http:\\www.gmail.com",0,1)
MsgBox(0,'Waiting....','',7)
For $i = 0 to Ubound($ieObjArray)-1
 _IEQuit($ieObjArray[$i])
Next
A decision is a powerful thing
Link to comment
Share on other sites

Is it possible to detect what obj quit?

OpenWebsite( 'http://www.google.com/')
OpenWebsite( 'http://www.autoitscript.com/')



While 1
    Sleep(50)
WEnd

Func OpenWebsite($url_IN)
Global $wait=1
ProgressOn($url_IN, "Loading page...")
$oInternet=ObjCreate("InternetExplorer.Application.1")    ; Create Internet Explorer application
$SinkObject=ObjEvent($oInternet,"IEEvent_","DWebBrowserEvents2"); Assign events to UDFs starting with IEEvent_
$oInternet.visible = 1
$oInternet.Navigate($url_IN); Opening a web page that contains a form
$IEWnd=HWnd($oInternet.hWnd)
While $wait=1
    Sleep(50)
WEnd
EndFunc


Func IEEvent_ProgressChange($Progress,$ProgressMax)
    $percent = Int( ($Progress * 100) / $ProgressMax )
    If $percent >= 0 And $percent <= 100 Then
        ProgressSet ( $percent , $percent & " percent to go." , "loading web page" )
    Else
        $wait=0
        ProgressOff()
    EndIf
EndFunc

Func IEEvent_OnQuit()
    MsgBox(0,'IE Msg','You closed a IE Window')
EndFunc
A decision is a powerful thing
Link to comment
Share on other sites

Check WinList. I think that should have what you want.

I suppose... but that would require the an Assign() to be used and the var updated with any navigationchanges in that object to be "recorded"...

that's doable

However, I wanted to see if it could be done with the Obj Event handler

A decision is a powerful thing
Link to comment
Share on other sites

Like this:

Global $count = 0
OpenWebsite( 'http://www.google.com/')
OpenWebsite( 'http://www.autoitscript.com/')



While 1
    Sleep(50)
WEnd

Func OpenWebsite($url_IN)
    $count+=1
Global $wait=1
ProgressOn($url_IN, "Loading page...")
$oInternet=ObjCreate("InternetExplorer.Application.1")    ; Create Internet Explorer application
$SinkObject=ObjEvent($oInternet,"IEEvent_","DWebBrowserEvents2"); Assign events to UDFs starting with IEEvent_
$oInternet.visible = 1
$oInternet.Navigate($url_IN); Opening a web page that contains a form
$IEWnd = HWnd($oInternet.hWnd)
If @error Then MsgBox(0,'','Could not get')
Assign('IEWnd'&$count,HWnd($oInternet.hWnd))
Assign('oIE'&$count,$oInternet,2)

While $wait=1
    Sleep(50)
WEnd
Assign('oIE_Title'&$count,$oInternet.document.title,2)
EndFunc


Func IEEvent_ProgressChange($Progress,$ProgressMax)
    $percent = Int( ($Progress * 100) / $ProgressMax )
    If $percent >= 0 And $percent <= 100 Then
        ProgressSet ( $percent , $percent & " percent to go." , "loading web page" )
    Else
        $wait=0
        ProgressOff()
    EndIf
EndFunc

Func IEEvent_OnQuit()   
    For $i = 1 to $count
        Local $o_object = Eval('oIE'&$i)
        local $title = Eval('oIE_Title'&$i);$o_object.document.title
        IF NOt WinExists($title) THen MsgBox(0,'IE Msg','You closed a IE Window'&@LF&Eval('oIE_Title'&$i),5)    
    Next
    
;$o_object.HWnd()
EndFunc

But that is not accurate and is a bit cumbersome

A decision is a powerful thing
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...