Embed Netscape's Mozilla Browser in MFC Views

Environment: Internet, Networking.

Introduction

This is an updated version of the article and source code I originally wrote, showing how to embed the ActiveX Control created by Adam Lock for the Mozilla Browser in CViews and Dialogs in MFC applications that 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, you should consider using the Mozilla Browser because 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 that 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 two 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:

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

Source Code

The source code for the demo project that goes with this article does NOT include the binary or source code for the Mozilla ActiveX Control because the source code for the Mozilla ActiveX Control is 4.5 megs and my Web site will not bear the download traffic! But, both the binary and full source code for the Mozilla ActiveX Control are available at the following locations:

http://ftp.mozilla.org/pub/mozilla/nightly/latest/embed-win32.zip
www.mozilla.org/ in subdirectory mozilla/embedding/browser/activex/src

Overview of the Mozilla ActiveX Control

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 IE. 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 IE 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, and so forth. This means that you can easily parse the contents of a page programmatically and even modify the page via the the Mozilla ActiveX Control. The control works any ActiveX control-compatible container, including IE HTML pages that can contain controls. The only thing you need to do is to register the single Mozilla control, mozctlx.dll, as follows:

Type and run "regsvr32 mozctlx.dll"

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;
  }
}

Using 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 Web site that demonstrates how to use this class.

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.
  • Voilá! 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 Web site, 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...

Anyone interested in new digital production techniques for shooting 35mm movies and new methods of syndicating television programming should call me or visit my Web site.

If you have any questions about this article or source code, please feel free to contact me. I have over 100 commercial software programs that you can purchase the source code for, as well as numerous systems for displaying advertising, with the user's full, informed consent, on millions of computers.

Bill SerGio, The Infomercial KingTM
http://www.software-rus.com
tvmogul1@yahoo.com
Wipeout61402@aol.com

Downloads

Download source - 288 Kb


Comments

  • The bvlgari purse Business organisation Presentation - Who cares wins??

    Posted by expopmerm on 03/22/2013 08:29pm

    Profitable strategies of bvlgari purse which can be used beginning today. [url=http://www.bvlgarishopjprie.com]ブルガリ[/url] The next fix for bvlgari purse which you can understand more about straight away. [url=http://www.bvlgarioutletshopjp.com]ブルガリブルガリ[/url] Check who's preaching about bvlgari purse and the reasons why you ought to be concerned. [url=http://www.bvlgarisalekodojp.com]ブルガリブルガリ[/url] Everything all others actually does when considering bvlgari purse and precisely what youwant to do different. [url=http://www.bvlgarisakaijpsale.com]ブルガリ[/url] The Astounding bvlgari purse 'cheat' That Are Designed To Fool Each and every one [url=http://www.bvlgariaokisalejp.com]ブルガリ 財布[/url] International Gossip : bvlgari purse Defined as A Must As of late mcm Will Highlight Brand-New Language : : We Move Down Into The Act [url=http://www.mcmbagsjphadori.com]mcm リュック[/url] Fresh, New Choices Into mcm Never Ever Before Uncovered [url=http://www.mcmstorejpkodo.com]mcm バッグ[/url] mcm Fake Pictures - - Wonderful mcm Cheat That Experts Claim Fools 96.4% Of The Purchasers [url=http://www.mcmoutletjpinoue.com]mcm 財布[/url] The thing that Most people Hates Over mcm And The particular reason why [url=http://www.mcmsalejapanoka.com]mcm バッグ[/url] mcm Adds Brand-New Lifespan To A Old Challenge: Defacto Industry-Standard [url=http://www.mcmzankijpshop.com]mcm リュック[/url] The Progressive mcm Technique Exposed By My Pal

    Reply
  • Quit Complaining , Start Off your own special adidas shoes Venture In exchange

    Posted by expopmerm on 03/18/2013 01:54am

    Brief blog post discloses the proven facts about adidas shoes and also how it can certainly effect anyone.|Quite short report shows you the cogs and wheels of nike shoes in addition to specifically what one ought to do this afternoon.}[url=http://www.nikejapan.asia/]nike air[/url] Precisely why not a single person is chatting about nike shoes and the things one should complete as we speak. [url=http://www.adidasjapan.biz/]adidas スニーカー[/url] nike shoes can provide completely new lifespan to the old dilemma. . . platinum general The Best Solutions To Develop gucci And Also How One Might Join The gucci bags Top dogs [url=http://www.guccijp.asia/]gucci 財布[/url] Ideal key for chloe that you may read about right now. [url=http://www.chloejp.biz/]財布 chloe[/url] How to discover all sorts of things there is to understand surrounding chanel in seven easy ways. [url=http://www.chaneljp.biz/]財布 chanel[/url] Easiest way to comprehend every thing there is to find regarding chanel in seven easy ways.The Father who just sold his very own adidas shoes script for 1 million [url=http://www.adidasjapan.asia/]アディダス シューズ[/url] Every double sprain on nike shoes [url=http://www.nikejp.biz/]ナイキスニーカー[/url] Specifically how to master every little thing there is to find relating to adidas shoes in eight easy ways.

    Reply
  • live sex chat shows webcam sex

    Posted by KefsAntence on 12/06/2012 08:53am

    Hi my friends thought I should give this a try so here goes, fed up with liars hoping to find someon. Originally from southeastern North Carolina, I'Ve been living in Miami, Florida working on my PhD. Im looking for a real man that would treat me well an. I can be a bit crazy (In a good way) but t. I am a working single mum of a beautiful little boy called Jake. I could say loads but then what would be the point in chatting. I am new to this site & dont really know how it all works. Hi ya! My name is Julie and I'M anything but ordinary. Hi all, I'M a short, friendly, slightly crazy person who is looking for new people to get to know.

    Reply
  • Things need to get it to work.

    Posted by Legacy on 11/10/2003 12:00am

    Originally posted by: Brian


    1. Use the CWebBrowser class, in the example app, or create your own.

    2. In view class create a CWebBrowser member, and repeate the create steps in the example, in the OnCreate function.

    3. Its now add however you cant see it?, One needs to now add the m_Browser ( or whatever ).SetWindowsPos, in the views OnSize function. Now you should see it.

    Note, may have to create a dumby resouce ID, go to resource view, right click the header, choose "resource =" from the context menu, click new, then add ( IDX_BROWSER ) or whatever is used the the m_Browser.create params.

    Reply
  • How to bypass intermediate html pages when using browser controls

    Posted by Legacy on 06/13/2003 12:00am

    Originally posted by: ShivSun

    I am using WebBrowser controls of MFC.I have specific requirement to write the html(response) pages obtained using the WebBrowser controls.So, I wrote a event handler to the OnDocumentComplete event.Inside the handler, I am caling the getDocument function and obtained the html page.When doing like this, the intermediate pages are also stored.I mean the pages which contain meta http-equvi=refresh.I need only the final response page that is diaplayed on the browser window.Is there any way to do this. Please help me. Can any of you tell me the usage and significance of the option OLECMDID_HTTPEQUIV in execWB()call.Will this be helpful to solve my issue.If so, please give me some ideas on its usage.

    Reply
  • IEMozilla

    Posted by Legacy on 05/29/2003 12:00am

    Originally posted by: Reunion

    What files from http://ftp.mozilla.org/pub/mozilla/nightly/latest/embed-win32.zip should I spread with my programm?

    Reply
  • what is the difference between yr stuff and "insert a ActiveX into a dialog"

    Posted by Legacy on 05/07/2003 12:00am

    Originally posted by: Bill Gates

    What is the point, man?

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Hurricane Sandy was one of the most destructive natural disasters that the United States has ever experienced. Read this success story to learn how Datto protected its partners and their customers with proactive business continuity planning, heroic employee efforts, and the right mix of technology and support. With storm surges over 12 feet, winds that exceeded 90 mph, and a diameter spanning more than 900 miles, Sandy resulted in power outages to approximately 7.5 million people, and caused an estimated $50 …

  • The impact of a data loss event can be significant. Real-time data is essential to remaining competitive. Many companies can no longer afford to rely on a truck arriving each day to take backup tapes offsite. For most companies, a cloud backup and recovery solution will eliminate, or significantly reduce, IT resources related to the mundane task of backup and allow your resources to be redeployed to more strategic projects. The cloud - can now be comfortable for you – with 100% recovery from anywhere all …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds