Click here to Skip to main content
Click here to Skip to main content

Find in CWebBrowser Control

, 10 Aug 2000
Rate this:
Please Sign up or sign in to vote.
How to display the "Find" window in a CWebBrowser control.

Introduction

An application that I had been assigned to write, required me to display reports that could possibly be over 10,000 lines in a CWebBrowser control. These 10,000 lines sometimes took a matter of hours to produce, so it was decided that it would be nice to display the report as it was generated, line by line. Being reasonably new to COM, I posted the question "How?" in the CodeProject message area. Along came Colin Davies, with a bit a code. In a 10,000 line report, it can take the user a lllloooonnnngggg time to find what they are looking for!

IE5 has the Edit - Find (on this page)... CTRL+F option that searches the current page. So I investigated implementing this in my CWebBrowser control, and found it was not as easy as it had first sounded to a COM newbie. Anyway after searching some rather confusing MSDN articles I hacked some code to produce this code slice, which can also be modified to display the View Source and Options windows as well.

Source listing

#include <initguid.h>
DEFINE_GUID(CGID_IWebBrowser,0xED016940L,
            0xBD5B,0x11cf,0xBA, 0x4E,0x00,
            0xC0,0x4F,0xD7,0x08,0x16);

//1 : FIND, 2: VIEWSOURCE, 3 : OPTIONS
DWORD nCmdID = 1; 

LPDISPATCH lpDispatch = NULL;
LPOLECOMMANDTARGET lpOleCommandTarget = NULL;

//m_htmlview is the member variable 
//for the CWebBrowser2 control.

lpDispatch = m_htmlview.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
lpOleCommandTarget->Exec(
        &CGID_IWebBrowser, nCmdID, 0,
        NULL, NULL);

// Release the command target
lpOleCommandTarget->Release();

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Jeremy Davis
Web Developer
United Kingdom United Kingdom
Is was a hardware engineer, that wrote the odd bit of MFC software. I am now training to become a technology teacher for 11 - 19 year olds.

Comments and Discussions

 
GeneralHandle to this dialog Pinmemberwill07070721-Sep-07 10:31 
GeneralApplet in WebBrowser Pinmembercolin-12313-Sep-06 0:49 
QuestionHow Can this be used IN C# Pinmemberjdnx21-Apr-06 23:16 
General10x Pinmembercata_100026-Sep-05 9:15 
GeneralSave as &quot;Web Page, complete&quot; Pinmemberleuven2-Jun-04 23:19 
GeneralRe: Save as &quot;Web Page, complete&quot; PinmemberIckis15-Jun-04 2:42 
GeneralRe: Save as &quot;Web Page, complete&quot; Pinmemberdrake2830-Dec-04 6:02 
Questionhow to navigate to HTML page from resouces Pinmembergeorge ivanov18-Dec-03 3:54 
AnswerRe: how to navigate to HTML page from resouces PinmemberJeremy Davis18-Dec-03 4:47 
QuestionCan I use it with CHtmlView PinmemberNaren7-Sep-02 3:39 
AnswerRe: Can I use it with CHtmlView Pinmembermmori14-Mar-04 12:23 
QuestionHow can I get the HTML text from Webbrowser Control ? PinmemberHiroshi2-Oct-01 3:23 
QuestionHow can I get the HTML text from Webbrowser Control ? PinmemberHiroshi2-Oct-01 3:22 
AnswerRe: How can I get the HTML text from Webbrowser Control ? Pinsusspawlb24-Oct-02 12:50 
GeneralThe arguments to the find method PinmemberTim Ford4-Jun-01 1:42 
GeneralRe: The arguments to the find method PinmemberJeremy Davis26-Jul-01 0:27 
QuestionGet explore device context..? Pinmemberdonghun lee22-Mar-01 19:53 
GeneralRight button -->> IE pop-up menu PinmemberAnonymous25-Feb-01 8:16 
GeneralRe: Right button -->> IE pop-up menu PinmemberJeremy Davis16-Mar-01 4:00 
GeneralRe: Right button -->> IE pop-up menu PinmemberBiri5-Jun-01 4:01 
GeneralRe: Right button -->> IE pop-up menu PinmemberKaЯl3-Jan-03 4:09 
GeneralRe: Right button -->> IE pop-up menu PinmemberJeremy Davis22-Aug-01 23:49 
Questionhow i can use it? Pinsussjaims15-Aug-00 17:12 
AnswerRe: how i can use it? PinsussJeremy Davis22-Aug-00 0:44 
GeneralSave As PinsussBrian Hart14-Aug-00 20:17 
GeneralPrinting PinsussBrian Hart26-Jul-00 7:48 
GeneralRe: Printing PinsussPeter Ierardi18-Aug-00 5:32 
GeneralRe: Printing problem any ideas? PinsussSteve29-Aug-00 3:41 
GeneralRe: Printing problem any ideas? PinsussJeremy Davis3-Sep-00 23:24 
GeneralRe: Printing problem any ideas? PinsussJeremy Davis3-Sep-00 23:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.1411022.1 | Last Updated 11 Aug 2000
Article Copyright 2000 by Jeremy Davis
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid