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);
DWORD nCmdID = 1;
LPDISPATCH lpDispatch = NULL;
LPOLECOMMANDTARGET lpOleCommandTarget = NULL;
lpDispatch = m_htmlview.GetDocument();
ASSERT(lpDispatch);
lpDispatch->QueryInterface(
IID_IOleCommandTarget,
(void**)&lpOleCommandTarget);
ASSERT(lpOleCommandTarget);
lpDispatch->Release();
lpOleCommandTarget->Exec(
&CGID_IWebBrowser, nCmdID, 0,
NULL, NULL);
lpOleCommandTarget->Release();