The Code Project Click here for the free Dundas Upload control
Home >> Miscellaneous Controls >> Unedited Reader Contributions

Find in CWebBrowser Control
By Jeremy Davis

How to display the "Find" window in a CWebBrowser control. 
 Beginner
 VC 4-6, Win95-98, NT4, W2K, MFC, COM
 Posted 29 Jun 2000
 Updated 11 Aug 2000
Articles by this author
Send to a friend
Printer friendly version
[This is an unedited reader contribution] [Modify this article] [Delete this article]
Latest Articles Logon Message Boards Submit an Article
Broken links? Email us!
11 users have rated this article. result:
4.64 out of 5.

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 that can be seen here. 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 aswell.


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

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

LPDISPATCH lpDispatch = NULL;
LPOLECOMMANDTARGET lpOleCommandTarget = NULL;

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();

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

[Top] Rate this Article for us!     PoorExcellent  
Hint: For improved responsiveness, use Internet Explorer 4 (or above) with Javascript enabled, choose 'Dynamic' from the View dropdown and hit 'Refresh'
 Keyword Filter
 View   Per page   Messages since
New threadMessages 1 to 10 of 11 (Total: 11)First | Prev | Next | Last
Subject 
Author 
Date 
  Get explore device context..?
donghun lee 0:53 23 Mar 01 
  Right button -->> IE pop-up menu
Anonymous 13:16 25 Feb 01 
  Re: Right button -->> IE pop-up menu
Jeremy Davis 9:00 16 Mar 01 
  how i can use it?
jaims 22:12 15 Aug 00 
  Re: how i can use it?
Jeremy Davis 5:44 22 Aug 00 
  Save As
Brian Hart 1:17 15 Aug 00 
  Printing
Brian Hart 12:48 26 Jul 00 
  Re: Printing
Peter Ierardi 10:32 18 Aug 00 
  Re: Printing problem any ideas?
Steve 8:41 29 Aug 00 
  Re: Printing problem any ideas?
Jeremy Davis 4:24 4 Sep 00 
Last Visit: 12:00 Friday 1st January, 1999First | Prev | Next | Last

Home >> Miscellaneous Controls >> Unedited Reader Contributions
last updated 11 Aug 2000
Article content copyright Jeremy Davis, 2000
everthing else © CodeProject, 1999-2001.
The Code Project Download Visual Build - Automate your software builds