Click here to Skip to main content
Click here to Skip to main content

Create SlickSkins™ with Netscape's Mozilla Browser in MFC Views

By , 23 Aug 2011
Rate this:
Please Sign up or sign in to vote.
Screenshot - iemozilla.gif

Introduction

I created SlickSkins™ back in 1992, and this article is an updated version of the article and source code I originally wrote showing how to create SlickSkins™ by embedding the ActiveX Control created by Adam Lock for the Mozilla Browser in CViews and Dialogs in MFC and creating non-rectangular skinned applications which can easily be extended for ATL applications as well.

I have never liked Microsoft's restrictive license agreement for Internet Explorer's ActiveX Control, i.e., their WebBrowser ActiveX Control. So if you want a browser that you can use in your applications sans Microsoft, then you should consider using the Mozilla Browser since the source code is available for free and it is very easy to compile and put in any MFC or ATL project. Let me point out that both Mozilla and the ActiveX Control for Mozilla are independent projects that are not associated with either Netscape or AOL.

The source code is available free for both the ActiveX Control for Mozilla and Mozilla itself. I was able to compile the source code for both the first time I tried it with NO problems whatsoever, and the binaries are available for those people who don't want to bother compiling the source code.

Anyone who looks at the source code for the native Gecko API calls will see that there are much better ways of doing things than just Microsoft's way. For example, you can use Gecko's powerful APIs which are implemented via XPCOM (COM-like) interfaces directly in your own code.

Anyone who has every run Mozilla on Linux and experienced its lightning fast speed will find it hard to go back to ever using the very slow and often buggy Internet Explorer!

The demo project included here creates a dynamic instance of either Microsoft's WebBrowser ActiveX Control or the Mozilla ActiveX Control in a CView of an MFC SDI application. It furthers allows you to switch between these 2 very different browsers by setting a single variable, m_bMozilla, in the CGlobal class or through a popup dialog that allows the user to select the browser to use as follows:

// Set condition for loading either 
CGlobal::CGlobal() 
     // or Mozilla's ActiveX Control { 
     // Microsoft's WebBrowser ActiveX Control  
     m_bMozilla = TRUE; 
}

Overview of Mozilla ActiveX Control

The source code for the demo project does NOT include the Mozilla ActiveX Control, MozillaControl1712, that you must download and install first.

You can download the Mozilla Control at:
http://www.iol.ie/~locka/mozilla/mozilla.htm

The direct link for the download is:
http://www.iol.ie/~locka/mozilla/MozillaControl1712.exe

The Mozilla ActiveX Control is implemented in ATL and it has a very small size of only 3 to 4MB for the Gecko embedding engine compared to over 10MB needed for Internet Explorer. What is really cool is that the Mozilla ActiveX Control has an API that is identical to that of Internet Explorer which makes it a breeze to implement in existing or new MFC and ATL applications because you can use your existing IE code with only a change in the CLSID. In other words, you only need to replace the CLSID_WebBrowser with CLSID_MozillaBrowser. VB developers just need to delete the Internet Explorer control from their project and insert a Mozilla one with the same instance name.

The Mozilla ActiveX Control implements the IWebBrowser, IWebBrowserApp, IWebBrowser2, DWebBrowserEvents, and DWebBrowserEvents2 interfaces defined for Internet Explorer. It also implements a simple DOM using the same COM interfaces as you find in Internet Explorer 4.0 for IHtmlDocument2, IHtmlElement, IHtmlElementCollection, etc. This means that you can easily parse the contents of a page programmatically and even modify the page via the Mozilla ActiveX Control. The control works any ActiveX control compatible container including IE HTML pages which can contain controls.

Using The Mozilla Control in C++

Included in the demo project with this article is a modified wrapper class that provides stub functions for creating and calling methods from either Microsoft's WebBrowser ActivexX Control or the Mozilla ActiveX Control.

// CWebBrowser2 wrapper class for Mozilla and IE WebBrowser Controls 
class CWebBrowser2 : public CWnd 
{ 
     protected: 
     DECLARE_DYNCREATE(CWebBrowser2) 
     public: 
     CLSID const& GetClsid() 
     { 
          if ( g_Global.m_bMozilla ) { 
          // For Mozilla ActiveX Control 
          static CLSID const clsid = { 0x1339b54c, 0x3453, 0x11d2, 
			{ 0x93, 0xb9, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 } }; 
          return clsid; 
     } else { 
          // For Microsoft WebBrowser ActiveX Control 
          static CLSID const clsid = { 0x8856f961, 0x340a, 0x11d0, 
			{ 0xa9, 0x6b, 0x0, 0xc0, 0x4f, 0xd7, 0x5, 0xa2 } }; 
          return clsid; 
     } 
}

To use the Mozilla ActiveX Control requires nothing more than simply replacing the reference to CLSID_Browser with CLSID_MozillaBrowser and declaring the CLSID_MozillaBrowser as follows:

static const CLSID CLSID_MozillaBrowser= 
{ 0x1339B54C, 0x3453, 0x11D2, { 0x93, 0xB9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } };

For ATL programmers and those who just hate MFC, you can simply use the CControlSite class that is part of the control and based on ATL and not MFC so it is lighter and more suitable for non-MFC projects. There is a sample project called "CBrowse" on the Mozilla website that demonstrates how to use this class.

How To Create SlickSkins™

To create SlickSkins™ regions, see my article at
http://www.codeproject.com/KB/audio-video/videoskins.aspx.

For Visual Basic Developers

To use the control in a Visual Basic:

  • Compile the control and ensure it is registered.
  • Right mouse over the VB control bar and select "Components...".
  • Choose "MozillaControl 1.0 Type Library" from the list of controls
  • Voila! The Mozilla ActiveX Control will appear in the toolbar and can be directly inserted into a project.
  • You can simply replace Microsoft's WebBrowser control now with the Mozilla control, that's it!

For Really Lazy Programmers

For really lazy programmers, there is even a tool on the Mozilla website called "IEPatcher" that will scan an executable or DLL and patch it to replace instances of the IE control with the Mozilla control. Just use the IEPatcher tool on an existing binary and that binary will then run using the Mozilla control instead of Microsoft's WebBrowser ActiveX control.

Remember guys and gals, think for yourself! Don't let Microsoft sell you a bill of goods that their way is the only way or the best way...

If you have any questions about this article or source code, please feel free to contact me.

Bill SerGio
tvmogul1@yahoo.com

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

William SerGio
CEO http://www.SerGioApps.com
United States United States
I am an investor who creates new products from Mobile Apps to nutritional supplements that I sell on national television in half hour infomercials and 30-second and 60-second TV Spots.
 
My main company buys and sells TV time to ad agencies in bulk which enables me to spin off new companies using the TV time I own. What most people don't know is that one half hour TV infomercial will gross from $100 MILLION to $500 million a year from TV sales alone.
 
Bill SerGio, CEO
www.SerGioApps.com
Follow on   Twitter

Comments and Discussions

 
GeneralMy vote of 5 PinmemberBill SerGio, The Infomercial King7-Jul-12 2:13 
GeneralMy vote of 5 PinmemberBill SerGio, The Infomercial King12-Jan-12 5:00 
GeneralRe: My vote of 5 PinmemberKochise23-May-12 0:33 
GeneralMy vote of 1 PinmemberRajeev Dhiman7-Nov-11 20:48 
GeneralMy vote of 5 PinmemberBill SerGio, The Infomercial King24-Oct-11 3:47 
GeneralMy vote of 5 PinmemberBill SerGio, The Infomercial King22-Sep-11 22:36 
GeneralMy vote of 5 PinmemberBill SerGio, The Infomercial King25-Aug-11 22:28 
GeneralMy vote of 1 Pinmembermuellerh25-Aug-11 20:06 
QuestionOld code that's no longer supported! PinmemberJim Crafton24-Aug-11 8:18 
AnswerRe: Old code that's no longer supported! PinmemberBill SerGio, The Infomercial King24-Aug-11 8:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web02 | 2.8.140415.2 | Last Updated 23 Aug 2011
Article Copyright 2011 by William SerGio
Everything else Copyright © CodeProject, 1999-2014
Terms of Use
Layout: fixed | fluid