CodeGuru
Earthweb Search
Forums Wireless Jars Gamelan Developer.com
CodeGuru Navigation
RSS Feeds

RSSAll

RSSVC++/C++

RSS.NET/C#

RSSVB

See more EarthWeb Network feeds

follow us on Twitter

Member Sign In
User ID:
Password:
Remember Me:
Forgot Password?
Not a member?
Click here for more information and to register.

Become a Marketplace Partner

jobs.internet.com

internet.commerce
Partners & Affiliates
















Home >> Visual C++ / C++ >> Internet & Networking >> Internet Protocols >> Browser Control


Using the Web Browser control (IE3)
Rating: none

Daniel Harth (view profile)
August 7, 1998

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.
(continued)




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.

Tools:
Add www.codeguru.com to your favorites
Add www.codeguru.com to your browser search box
IE 7 | Firefox 2.0 | Firefox 1.5.x
Receive news via our XML/RSS feed







RATE THIS ARTICLE:   Excellent  Very Good  Average  Below Average  Poor  

(You must be signed in to rank an article. Not a member? Click here to register)

Latest Comments:
How to change the Web browser's status bar's font color programatically - Legacy CodeGuru (09/30/2003)
Microsoft Web Browser Object in a Dialog window ? - Legacy CodeGuru (04/09/2003)
Can you force the control to scroll to the bottom of the page ? - Legacy CodeGuru (03/14/2003)
window.open doesn't pass cookie in app - Legacy CodeGuru (01/21/2003)
Is this control available for CE? - Legacy CodeGuru (04/28/2002)

View All Comments
Add a Comment:
Title:
Comment:
Pre-Formatted: Check this if you want the text to display with the formatting as typed (good for source code)



(You must be signed in to comment on an article. Not a member? Click here to register)