title: Handle HTMLElementEvents2 when DWebBrowserEvents2 has been handled using ATL's macros
body: <p>I'm creating a Browser Helper Object using VS2008, C++. My class has been derived from IDispEventImpl among many others</p>
  
  <pre><code>class ATL_NO_VTABLE CHelloWorldBHO :
      public CComObjectRootEx&lt;CComSingleThreadModel&gt;,
      public CComCoClass&lt;CHelloWorldBHO, &amp;CLSID_HelloWorldBHO&gt;,
      public IObjectWithSiteImpl&lt;CHelloWorldBHO&gt;,
      public IDispatchImpl&lt;IHelloWorldBHO, &amp;IID_IHelloWorldBHO, &amp;LIBID_HelloWorldLib, /*wMajor =*/ 1, /*wMinor =*/ 0&gt;,
      public IDispEventImpl&lt;1, CHelloWorldBHO, &amp;DIID_DWebBrowserEvents2, &amp;LIBID_SHDocVw, 1, 1&gt;
  
  {
  .
  .
  .
  BEGIN_SINK_MAP(CHelloWorldBHO)
       SINK_ENTRY_EX(1, DIID_DWebBrowserEvents2, DISPID_DOCUMENTCOMPLETE, OnDocumentComplete)
       SINK_ENTRY_EX(1, DIID_DWebBrowserEvents2, DISPID_BEFORENAVIGATE2, BeforeNavigate2)//Handle BeforeNavigate2
  END_SINK_MAP()
  .
  .
  .
  }
  </code></pre>
  
  <p>As apparent from the code above, my DWebBrowserEvents2 are handled using the ATL's macros. Now I want to handle  HTMLElementEvents2 (to detect clicks, scrollbars, etc.) For that, I QueryInterface() the IHTMLDocument2 object for IHTMLElement, QueryInterface() that for IConnectionPointContainer and call IConnectionPointContainer::FindConnectionPoint(DIID_HTMLElementEvents2). (See <a href="http://msdn.microsoft.com/en-us/library/bb508508(VS.85).aspx" rel="nofollow noreferrer">msdn's article</a> on handling HTMLElementEvents2). The problem is, when I overwrite IDispatch::Invoke in my class, the DWebBrowserEvents2 handles (created using ATL macros) fail. Is there a way to handle HTMLElementEvents2 without overwriting Invoke, or implement invoke in such a way that it only handles HTMLElementEvents2?<br/>
  Thanks, Any help will be appreciated.</p>