WebBrowser Goodies

I have worked with Microsoft WebBrowser control, MSHTML (the HTML parsing and rendering engine behind the WebBrowser control) and Internet Explorer quite a bit, and I have gained a lot of experience and information about them.  I have several articles on this subject, each of which cover a certain point about the topics mentioned above.  Here is a list of articles on this subject; I will update this list as I add newer articles.  Some of the articles on this list you may already have seen, the others are new.  I have also provided a short description on what each article is about.  Hope they will be useful to you.

Usually when you want to load some HTML content into a WebBrowser control, you have to create an HTML page (either as a resource, or as a separate file) and then navigate to that page.  But there is another more flexible way to add HTML content to the WebBrowser control on the fly.  This article introduces a C++ class which can be used to simplify the details of adding HTML content dynamically.

If an application implements some standard interfaces, such as IDocHostUIHandler, IDocHostUIHandler2, and IDocHostShowUI, it can gain a lot of flexibility on how the WebBrowser control acts and looks.  Implementing those interfaces is a bit trick, especially when it comes to use them with CHtmlView as well.  I have written a set of classes which simplify the details of implementing those interfaces, and enable you to override WebBrowser’s behavior by implementing a set of virtual functions.  All information about this subject is covered in this article.

This article demonstrates how to change the registry settings to change the behavior of the WebBrowser control.  The sample application is this article toggles the Show Picture setting of the WebBrowser control from on to off and vice versa.  The sample also demonstrates how to write a simple and small Unicode program as well.  See the Why to Use Unicode and Unicode articles for more information.

Many of the applications which host the WebBrowser control need to implement some common commands which apply to almost any application.  This can be implementing the View Source feature, showing the Properties dialog, invoking the Find command, etc.  This article gathers many parts of one of my applications which hosts the WebBrowser control, and using the sample code of this article, you will be able to implement almost every feature on Internet Explorer in your own applications.

Most of the time, you don’t want the standard context menu of the WebBrowser control inside your applications.  You may want to show a completely customized menu, or add or remove items to the standard context menu.  This article divides all the possible cases into three scenarios, and fully describes the steps you need to take to customize the context menu in any way you’d like.

The WebBrowser control needs to show message boxes on different occasions.  You may want to disable those message boxes altogether, log them to log files, change the way the message boxes look, change their title, or display a completely customized user interface.  This article shows how to intercept the default behavior of the WebBrowser control in this regard.

Many of the WebBrowser control’s settings can be altered via the registry, and all you need to do is to change registry keys and values.  An application can ask the WebBrowser control to change the location it reads the settings from to a completely custom registry key, and this way, customize the settings for the WebBrowser control in their own applications while leaving other application which use the WebBrowser control (including Internet Explorer) intact.  This article shows how you should do this.

An HTML user interface would be of little use if you can’t communicate from the HTML page to your application’s code and vice versa.  While this may seem impossible, all you need to do to make this work is to write a COM object, and provide the communication from the scripts inside the page to the C++ code via that object.  This article demonstrates how this can be done, and the sample application how a simple object can communicate between the script code and the C++ code easily.

This article shows how to use MSHTML to display HTML dialogs.  HTML dialogs are great UI elements which can be created with little effort on your part.  The C++ class presented in this article turns displaying a modal HTML dialog into a set of simple function calls.

This utility application is a spy tool for monitoring the WebBrowser control instances created in the system (even in other processes), and shows how to execute commands on those WebBrowser controls.  For example, using this utility, you can instantly view the HTML source for any WebBrowser control’s contents you want!  This tool comes with the source code.

This article originally appeared on BeginThread.com. It’s been republished here, and may contain modifications from the original article.

Posted in Visual C++

Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>