IE Automation

  • Thread starter Thread starter Daniel B. Harwood
  • Start date Start date
D

Daniel B. Harwood

Using C# Standard Edition 2003 (a bargain!), I have
written a multi-threaded Windows forms application which
checks Web sites of interest for newly posted Web pages.
On detecting a new page it announces it using the Speech
API (mini tutorial on speech at bottom).

I opted to check each Web site with a separate worker
thread to prevent slow sites from bringing the whole
process to a grinding halt.

Unfortunately I appear to have hit a brick wall when it
comes to sites with frames as the InternetExplorer object
does not appear to support the IHTMLDocument2::frames
interface.

Despite extensive searching on MSDN and Google I can find
nothing on this. Can anyone confirm my finding above and
possibly offer a workaround?

I have found that if I embed a "Microsoft Web Browser"
control on the windows form, I can access the frames
interface. I suppose I could create multiple browser
controls at run-time, but...

Cheers,

Daniel.

Mini Tutorial - How to use the Speech API (SAPI) to say
something:

1. Add a reference to the "Microsoft Speech Object
Library" COM object to your project.

2. Add the following using statement to your code:
using SpeechLib;

3. Use the following code to say something (keep it
clean!):

SpeechVoiceSpeakFlags SpFlags =
SpeechVoiceSpeakFlags.SVSFlagsAsync;
SpVoice speech = new SpVoice();
speech.Speak("Hi there", SpFlags);
 
Daniel B. Harwood said:
I opted to check each Web site with a separate worker
thread to prevent slow sites from bringing the whole
process to a grinding halt.

Unfortunately I appear to have hit a brick wall when it
comes to sites with frames as the InternetExplorer object
does not appear to support the IHTMLDocument2::frames
interface.
Despite extensive searching on MSDN and Google I can find
nothing on this. Can anyone confirm my finding above and
possibly offer a workaround?

Accessing frames from the exposed IE COM API is tricky, but I found that
there is a reliable way of doing it 3 years ago in VB, which *should* work
for the .NET interop. Hopefully this will give some pointers!...

Firstly, look trap the NavigateComplete2 event for the IE instance. This
will be fired for *each frame* on a multi-frame document (including the page
that constructs the frameset).

An argument to this event should be something called pDisp, of type Object.
You should be able to cast this to an IE Window, and it should have a
Document property - which is the HTMLDocument (or IHTMLDocument2) or the
frame. At this point you now should now have a reference to each frame in
the multi-frame page to do whatever you want with!

One thing to remember: at this point the page will not have loaded, so
accessing contents may not work. You'll want to use the DocumentComplete
event to trigger the analysis of the page.

I have found that if I embed a "Microsoft Web Browser"
control on the windows form, I can access the frames
interface. I suppose I could create multiple browser
controls at run-time, but...

One problem I had with using the Frames collection was security exceptions
if the frames were from multiple URLs. Is this still an issue?

The speechlib intro is useful, I had no idea it was so simple - thanks!

HTH

Tobin Harris

P.S - in case you're interested, I learnt a bit about this IE stuff when
writing a utility that detected and hooked into running instances of IE. It
logged every visit to all URLs, including those with framesets, and recorded
the users activities such as scrolling, searching etc, visit time etc. This
data was consumed by an intelligent agent which would help the user by
determining their browsing intent and adjusting their experience
accordingly. Gotta love that CS degree!
 
For my app. trapping just the DocumentComplete event was
the answer, where as you described, I can cast the pDisp
parameter as IWebBrowser2 and retrieve the IHTMLDocument2
interface for each frame.

Cheers,

Daniel H.
 
Back
Top