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 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.

Comments
How to change the Web browser's status bar's font color programatically
Posted by Legacy on 09/30/2003 12:00amOriginally posted by: karthi_dac2000
hi..
ReplyIs it possible to change the color of the status bar of the Web browser?
Can you force the control to scroll to the bottom of the page ?
Posted by Legacy on 03/14/2003 12:00amOriginally posted by: Steve Stone
I want to scroll the view to the bottom of the html page.
Replywindow.open doesn't pass cookie in app
Posted by Legacy on 01/21/2003 12:00amOriginally posted by: Boscowall
Anyone know how to make window.open pass on the cookie to the new window? we have some popups in our app that embeds IE, but it never has the same cookie as the parent window. Any help would be nice...
-
Replysame question
Posted by Dumer on 03/24/2006 05:36amHello, Does anyone solve this problem? I would be interesting by the solution.. Thanks
ReplyIs this control available for CE?
Posted by Legacy on 04/28/2002 12:00amOriginally posted by: IUnknown
; )
ReplyWebBrowser sans MFC and all that crap
Posted by Legacy on 04/16/2002 12:00amOriginally posted by: adam
I only put the section of code that actually creates the WebBrowser here, but feel free to email me for the whole thing. The only thing i can't figure out is how to do an event sink without MFC and ATL etc. Please email me or post on how to do that.
// note, site is a derrived class from IOleClientSite and IOleInPlaceSite
// and storage is a derrived class from IStorage
IOleObject* mpWebObject;
OleCreate(CLSID_WebBrowser,IID_IOleObject,OLERENDER_DRAW,0,&site,&storage,(void**)&mpWebObject);
mpWebObject->SetHostNames(L"Web Host",L"Web View");
RECT rect;
GetClientRect(hwnd,&rect);
mpWebObject->DoVerb(OLEIVERB_SHOW,NULL,&site,-1,hwnd,&rect);
IWebBrowser2* iBrowser;
mpWebObject->QueryInterface(IID_IWebBrowser2,(void**)&iBrowser);
IUnknown *pUnk;
sink->QueryInterface(IID_IUnknown, (void**)&pUnk);
Sink(mpWebObject, pUnk);
VARIANT vURL;
vURL.vt = VT_BSTR;
vURL.bstrVal = SysAllocString(L"www.yahoo.com");
VARIANT ve1, ve2, ve3, ve4;
ve1.vt = VT_EMPTY;
ve2.vt = VT_EMPTY;
ve3.vt = VT_EMPTY;
ve4.vt = VT_EMPTY;
iBrowser->put_Left(0);
iBrowser->put_Top(0);
iBrowser->put_Width(rect.right);
iBrowser->put_Height(rect.bottom);
iBrowser->Navigate2(&vURL, &ve1, &ve2, &ve3, &ve4);
VariantClear(&vURL);
iBrowser->Release();
ReplyHow do you create a WebBrowser control with just ActiveX and COM
Posted by Legacy on 04/15/2002 12:00amOriginally posted by: adam
How do you create a WebBrowser control in a straight Win32 API created window without any wrapper classes, ATL, visual editing, or any of that, just straight ActiveX and COM? I've been trying to figure out how to do this for a couple of weeks now and haven't had any success. Please help.
ReplyThank you,
adam
Viewing a resource HTML file with WebBrowser control
Posted by Legacy on 01/27/2002 12:00amOriginally posted by: Bill G.
I'm fairly new to Visual C++ and I'm having trouble accessing an HTML file that's a resource. I don't have any problem accessing websites using the following code:
m_browser.Navigate("www.yahoo.com", NULL, NULL, NULL, NULL);
I have imported an HTML file as a resource, but I can't figure out how to display it in the WebBrowser control. Can anyone help?
Thanks,
ReplyBill G.
How Can I have a Web Browser control change views ONLY when the new file is done downloading?
Posted by Legacy on 12/24/2001 12:00amOriginally posted by: Blake Caldwell
i'm tryin to have an html window in my dialog. the problem is, i dont want the user to see the transition between the two pages.
but, it's very important that the download be able to log a hit on a page...cause i want this to be able to have an ad from some company, where the download logs that the user has seen the banner.
Thanks.
email me:
blake@pluginbox.com
Blake Caldwell
Replystudent, MFC programmer
How to bind with a RAS connection
Posted by Legacy on 08/30/2001 12:00amOriginally posted by: Manfred Hackstock
it is possible to bind a CWebbrowser control to a IP address which I get from a RAS connection.
Thanks in advance
ReplyManfred hackstock
How to Intercept Click on File
Posted by Legacy on 06/14/2001 12:00amOriginally posted by: Carl Vachon
I would like tou Intercept Left Mouse Click for override Browse File Select Dialog...
Can you help me PLZ..
Thanks
ReplyCarl Vachon
Loading, Please Wait ...