Invoke Find, View Source, Options Dialog Boxes for WebBrowser
ID: Q175513
|
The information in this article applies to:
-
Microsoft Internet Explorer (Programming) versions 3.0, 3.01, 3.02, 4.0, 4.01, 5
SUMMARY
This article illustrates how to invoke the Internet Explorer Find, Internet
Options, and View Source dialog boxes from within an application that is
hosting the WebBrowser control.
The following files are available for download from the Microsoft
Download Center. Click the file names below to download the files:
Wbsample.exe For more information about how to download files from the Microsoft
Download Center, please visit the Download Center at the following Web
address
http://www.microsoft.com/downloads/search.asp
and then click How to use the Microsoft Download Center.
MORE INFORMATIONWARNING: This sample uses an undocumented command group GUID that is
subject to change in the future. Although this sample has been tested to
work correctly with Internet Explorer 3.0 and 4.0, there is no guarantee
that these techniques will continue to work successfully in future
versions. Please use caution when adding this code to an application.
The WBSampl example is a mini-browser application that illustrates how to
create an application in Microsoft Visual C++ that uses the WebBrowser
control. This example provides code to invoke the Find, Internet Options,
and View Source items that are part of the WebBrowser control but are not
exposed as methods.
In order to implement the items listed above, the following steps should be
followed.
- Define the command group GUID for the WebBrowser control as follows:
DEFINE_GUID(CGID_IWebBrowser,0xED016940L,0xBD5B,0x11cf,0xBA,
0x4E,0x00,0xC0,0x4F,0xD7,0x08,0x16);
- Define the CommandTarget ids for menu driving as follows:
#define HTMLID_FIND 1
#define HTMLID_VIEWSOURCE 2
#define HTMLID_OPTIONS 3
- Execute a CommandTarget id as follows:
HRESULT CMainFrame::ExecCmdTarget(DWORD nCmdID)
{
LPDISPATCH lpDispatch = NULL;
LPOLECOMMANDTARGET lpOleCommandTarget = NULL;
lpDispatch =
((CWebSurferView*)GetActiveView())->m_webBrowser.GetDocument();
ASSERT(lpDispatch);
// Get an IDispatch pointer for the IOleCommandTarget interface.
lpDispatch->QueryInterface(IID_IOleCommandTarget,
(void**)&lpOleCommandTarget);
ASSERT(lpOleCommandTarget);
lpDispatch->Release();
// Invoke the given command id for the WebBrowser control
return lpOleCommandTarget->Exec(&CGID_IWebBrowser, nCmdID, 0,
NULL, NULL);
}
Note that m_webBrowser is an instance of the WebBrowser control and is
defined in the CView-derived class for this project. Also, nCmdID is one
of the IDs defined in step 2.
© Microsoft Corporation 1997, All Rights Reserved. Contributions by Scott Roberts, Microsoft Corporation
Additional query words:
WebBrowser WBSampl Find Source Options Internet Explorer IE
Keywords : kbfile kbsample kbIE300 kbIE301 kbIE400 kbIE401 kbWebBrowser kbIE302 kbIE500 kbDSupport kbIEFAQ
Version : WINDOWS:3.0,3.01,3.02,4.0,4.01,5
Platform : WINDOWS
Issue type : kbinfo
|