5

我正在运行 BHO,我正在尝试使用 HTMLDocumentEvents2 捕获 OnClick 事件,但是这些事件似乎永远不会到达处理程序

这就是我正在做的事情:

class ATL_NO_VTABLE CBlastBhoBHO :
  public CComObjectRootEx<CComSingleThreadModel>,
  public CComCoClass<CBlastBhoBHO, &CLSID_BlastBhoBHO>,
  public IObjectWithSiteImpl<CBlastBhoBHO>,
  public IDispatchImpl<IBlastBhoBHO, &IID_IBlastBhoBHO, &LIBID_BlastBhoLib, /*wMajor     =*/ 1, /*wMinor =*/ 0>,
  public IDispEventImpl<0, CBlastBhoBHO, &DIID_HTMLDocumentEvents2, &LIBID_MSHTML, 1, 0>,
  public IDispEventImpl<1, CBlastBhoBHO, &DIID_DWebBrowserEvents2, &LIBID_SHDocVw, 1, 1>



BEGIN_SINK_MAP(CBlastBhoBHO)
SINK_ENTRY_EX(0, DIID_HTMLDocumentEvents2, DISPID_HTMLDOCUMENTEVENTS2_ONCLICK,   OnClickTrigger)
SINK_ENTRY_EX(1, DIID_DWebBrowserEvents2, DISPID_DOCUMENTCOMPLETE,      OnDocumentComplete)
END_SINK_MAP()


// Handlers
void STDMETHODCALLTYPE CBlastBhoBHO::OnDocumentComplete( IDispatch *pDisp, VARIANT *url) { // works fine }
void STDMETHODCALLTYPE CBlastBhoBHO::OnClickTrigger(IHTMLEventObj *pEvtObj) { // Never called }

// From SetSite()
  ATL::IDispEventSimpleImpl<1,CBlastBhoBHO,&DIID_DWebBrowserEvents2>::DispEventAdvise(m_spWebBrowser); 


// From OnDocumentComplete
 CComQIPtr<IHTMLDocument3> doc_;
m_spWebBrowser->get_Document((IDispatch**) &doc_);
ATL::IDispEventSimpleImpl<0,CBlastBhoBHO,&DIID_HTMLDocumentEvents2>::DispEventAdvise(doc_);

我尝试了几种变体(使用 HTMLElementEvents2 等)或就不同的对象提供建议或就 SetSite 的文档提供建议。我的处理程序永远不会被调用。

任何帮助将非常感激。我只需要 onClick 事件。

4

2 回答 2

1

可能是因为LIBID_MSHTML的版本不匹配,试试改成4.0版本,即全部改

IDispEventImpl<0, CBlastBhoBHO, &DIID_HTMLDocumentEvents2, &LIBID_MSHTML, 1, 0>

IDispEventImpl<0, CBlastBhoBHO, &DIID_HTMLDocumentEvents2, &LIBID_MSHTML, 4, 0>

于 2010-05-26T13:36:27.687 回答
0

试试这个功能 -

VARIANT_BOOL attachEvent( _bstr_t event, IDispatch *pdisp)

前任:-

MSHTML::IHTMLDocument3Ptr pDoc3 = 0;
pDoc.QueryInterface(IID_IHTMLDocument3,&pDoc3);
IDispatchEx evtClick;

pDoc3->attachEvent(_bstr_t(L"onclick"),&evtClick);
于 2010-07-02T13:55:45.387 回答