Working With MSHTML Hosting

On the surface it seems like a great deal. You can actually embed MSHTML, the IE HTML rendering engine, in your own application. There is a lot of cool, simple features you get out-of-the-box. As soon as you get more advanced in your features, you find things are not so simple.

First, lets clear up some terminology:

  • WebBrowser – is an ActiveX control that you can embed in your applications to create a mini webbrowser. It will display HTML pages just as well as IE itself.
  • MSHTML – is a set of COM interfaces that you can use to programmatically access the elements of an HTML page. The interfaces also allow you to take part in Dynamic HTML events as well as behind the scenes operations like editing, custom rendering and behaviors, and selection.

WebBrowser depends on MSHTML. In fact there is not much beyond navigating to an HTML page that you can do with WebBrowser alone.

Myself and my team have become quite familiar with the ins and outs of MSHTML hosting. Never have I seen a more clear case of the 80/20 rule. MSHTML will get you 80% of your features very quickly and with relative ease. That last 20% will break most of you.

By no means do I consider myself an expert on MSHTML hosting, but I have implemented some tough features. One of the hardest things about moving past the beginner level stuff is the lack of real examples. I thought I would collect some links to stuff I found useful and post some code examples as well.

More to come

5 Comments

  1. Anonymous said,

    October 26, 2004 @ 3:20 pm

    Hi Mark
    I am trying to make IE toolbar in C# by using code appeared on CodeProject Site “Extending BandObjects in Dot.net” something like that

    I want to Implment OnDocumentComplete Event and want to perform things under this event instead of Click,since i am making IE toolbar so i dont need WebBrowser Control,am I right?how can I do this

    Thanks

    adnan(http://adynan.cjb.net)

  2. Anonymous said,

    October 26, 2004 @ 3:20 pm

    Hi Mark
    I am trying to make IE toolbar in C# by using code appeared on CodeProject Site “Extending BandObjects in Dot.net” something like that

    I want to Implment OnDocumentComplete Event and want to perform things under this event instead of Click,since i am making IE toolbar so i dont need WebBrowser Control,am I right?how can I do this

    Thanks

    adnan(http://adynan.cjb.net)

  3. Mark Finkle said,

    October 27, 2004 @ 11:27 pm

    Sounds like you want to be notified when the main IE window has finished loading its HTML. In this case, you do not want your own WebBrowser. You only need one if you want to display HTML in your BandObject.

    Trying to attach to the IWebBrowser events, as you have, is the best way. Did you see this article on CodeProject [http://www.codeproject.com/buglist/iefix.asp] about potential problems hooking to events using .NET?

    Another possible way would be polling the IWebBrowser::ReadyState, waiting until it returns “complete”.

  4. Anonymous said,

    May 14, 2005 @ 8:14 am

    Hi, Mark!
    I’m interested in your opinion on the 80/20 rule that you mention.

    I’m working on a project where it INDEED would be very beneficial to be able to embed the WebBrowser component within my own application framework. But I’m beginning to suspect that those last 20% might be very hard to pin down, and I’m even suspecting that it might be close to impossible. And I guess the reason for my doubts is that I’ve seen so EXTREMELY few successful stories of WebBrowser embedding.

    So, I guess I’m looking to you to hear whether you managed to pull through with it, and whether you managed to embed the component in a way that made it work AS good as when using the ordinary Internet Explorer application. That’s my question.

    I’m wondering if it’s POSSIBLE, or if there will always remain some catch-22′s when using the WebBrowser ActiveX to embed web browsing functionality within another application.

    Thanks,
    Elling

  5. Mark Finkle said,

    May 19, 2005 @ 12:05 pm

    Depends on the type of functionality you need. Some of the hard stuff for my applications are:
    - Printing horizontally across pages
    - Rendering to metafiles
    - Editing tables (selection and resizing)

    When using the control to browse HTML content (like a web browser), you can do nearly everything IE could do. I say “nearly” because I assume that 100% IE functionality is not possible, but I have not hit any issues yet in my code.

    When trying to use the control for non-HTML browsing is where you can run into problems that cannot be worked around.

RSS feed for comments on this post