"Hans-J. Ude" <news@s237965939.online.de> wrote in message
news:6qgangFceuhhU1@mid.individual.net...
From an external browser object I know nothing more about it than it's
IHTMLDocument2 interface. The question is: how can I catch the
NavigateComplete event, resp. install/uninstall a handler for that
event? If someone knows a better group or a web resource for that
question, please tell me. This low level COM programming in C++ is
really a tough job.
Hans
Here's an outline of what you want:
// You already have the ITHMLDocument2
CComPtr<IHTMLDocument2> spDoc;
// Ask the ServiceProvider for IWebBrowser2
CComQIPtr<IServiceProvider> spIsp(spDoc);
CComPtr<IWebBrowser2> spWebBrowser2;
spIsp->QueryService(SID_SWebBrowserApp, IID_IWebBrowser2,
(LPVOID*)&spWebBrowser2);
if ( !spWebBrowser2 )
return FALSE;
// Sign up for IWebBrowser2 events
CComQIPtr<IConnectionPointContainer> spCPC(pWebBrowser2); // get the
WebBrowser's ConnectionPointContainer
if (spCPC)
{
// get the WebBrowserEvents2 connection point in the container
HRESULT hr = spCPC->FindConnectionPoint(DIID_DWebBrowserEvents2,
&m_pConnectionPoint);
if (m_pConnectionPoint)
{
// Start getting WebBrowser notifications. Invoke() will be called back.
m_pConnectionPoint->AddRef();
m_pConnectionPoint->Advise(this, &m_dwAdviseCookie); // 'this' is an
object derived from IDispatch; IDispatch::Invoke will be called with
DISPID_DOCUMENTCOMPLETE
}
m_pWebBrowser2->AddRef(); // don't let the IWebBrowser2 go away
until 'this' object goes out of scope when we're done sinking events
Thanks David, that looks very interesting. I'll try that out some of the
next days.