Using the Web Browser control (IE3) | CodeGuru

Using the Web Browser control (IE3)

Internet Explorer 3+ comes with a Web Browser ActiveX control that you can use to add HTML viewing capabilities to your application. In fact, IExplore.exe is a very small application that is simply a host for this control. The most important interface that is used to interact with it is IWebBrowser, declared in the exdisp.h […]

Written By
CodeGuru Staff
CodeGuru Staff
Aug 7, 1998
2 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

Internet Explorer 3+ comes with a Web Browser ActiveX
control that you can use to add HTML viewing capabilities to your application.
In fact, IExplore.exe is a very small application that is simply a host
for this control. The most important interface that is used to interact
with it is IWebBrowser, declared in the exdisp.h file that
is included with Visual C 5.0. The newer IWebBrowser2 interface
adds a few new methods but is only supported by Internet Explorer 4, and
its definition is not included with Visual C 5.0. However you can use Developer
Studio to generate a wrapper class for it.

The Visual C 5.0 uuid.lib doesnt include the definition
of IID_IWebBrowser and CLSID_WebBrowser, but these GUIDs can be easly found
in exdisp.h or the registry. This is what I came up this:

/* EAB22AC1-30C1-11CF-A7EB-0000C05BAE0B
*/


IID const IID_IWebBrowser={0xEAB22AC1,
0x30C1, 0x11CF, 0xA7, 0xEB, 0x00, 0x00, 0xC0, 0x5B, 0xAE, 0x0B};

/* 8856F961-340A-11D0-A96B-00C04FD705A2
*/


CLSID const CLSID_WebBrowser={0x8856F961,
0x340A, 0x11D0, 0xA9, 0x6B, 0x00, 0xC0, 0x4F, 0xD7, 0x05, 0xA2};

You can use an ActiveX control in you application by using
CWnd::CreateControl. Make sure that you call AfxEnableControlContainer()
in your CWinApp::InitInstance(). After you created it you can use
CWnd::GetControlUnknown to retreive the controls IUnknown and then you
can QueryInterface it for IID_IWebBrowser.

m_wndBrowser.CreateControl(CLSID_WebBrowser,
lpszWindowName, WS_VISIBLE|WS_CHILD, rect, this, AFX_IDW_PANE_FIRST);


IUnknown *pUnk=m_wndBrowser.GetControlUnknown();

IWebBrowser *pBrowser;

HRESULT hr=pUnk->QueryInterface(IID_IWebBrowser,
(void **)&pBrowser);

After the control is set up you can use the Navigate
method to browse a page.

CString url(“http://www.microsoft.com/”);

BSTR bUrl=url.AllocSysString();

COleVariant vNull(LPCTSTR)NULL,
VT_BSTR);


hr=pBrowser->Navigate(bUrl, &vNull,
&VNull, &vNull, &vNull);

The example I wrote views a web page in a MDI child window.
Click here to download it. For more information
on this control download the Internet Client SDK documentation that is
available at Microsofts web site.



CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.