Share via


Setting Up Event Sinks (Windows CE 5.0)

Send Feedback

After you create the Web browser object as described in Creating a Browser Window, you must register your event sinks. To do this, retrieve a connection point container, on an IConnectionPointContainer interface, for the Web browser object, IWebBrowser2. Use the FindConnectionPoint method on IConnectionPointContainer to retrieve the connection point for the DWebBrowserEvents2 interface. Then, call Advise on the IConnectionPoint interface to register the client's event sink with the connection point. When browser events are fired through Invoke, the registered event sink gets called.

The following code example show a method defined in the browser class, RegisterBrowserEventSink that establishes a connection between the connection point of the IWebBrowser2 object and the event sink to call.

HRESULT CBrowser::RegisterBrowserEventSink()
{
  HRESULT     hr = S_FALSE;
  IConnectionPointContainer  *pCPCont = NULL;
  DWebBrowserEvents2          *pEvents = NULL;
  if (!_pWB2)
      goto Cleanup;
// Get the connection point container for the browser object.
  hr = _pWB2->QueryInterface(IID_IConnectionPointContainer, (LPVOID *)&pCPCont);
  if (FAILED(hr))
  {
      hr = S_FALSE;
      goto Cleanup;
  }
// Look for DWebBrowserEvents2 connection point.
  hr = pCPCont->FindConnectionPoint(DIID_DWebBrowserEvents2, &_pCP);
  if (FAILED(hr))
  {
      _pCP = NULL;
      goto Cleanup;
  }
// Get a DWebBrowserEvents2 pointer from the browser.
  hr = QueryInterface(DIID_DWebBrowserEvents2, (LPVOID *)(&pEvents));
  if (FAILED(hr))
      goto Cleanup;
// Add your event sink to the connectionpoint.
  hr = _pCP->Advise(pEvents, &(_dwEventCookie));
  if (FAILED(hr))
      goto Cleanup;
Cleanup:
  if (pCPCont)
      pCPCont->Release();
  if (pEvents)
      pEvents->Release();
  return hr;
}

See Also

Navigating to a Specified URL | Creating an Internet Browser

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.