首先需要再BHO中维护一个IWebbrowser2接口,然后通过这个接口获得一个IHTMLDocument2接口,然后通过择个接口获得ICustomDoc 借口,然后通过ICustomDoc 接口的SetUIHandle方法将自己的IDocHostUIHandler实现连接到IE上面:
HRESULT CFindHook::ChangeUIHandler()
{
CComPtr<IDispatch> spDoc;
m_spWebBrowser2->get_Document(&spDoc);
CComPtr<ICustomDoc> spCustomDoc;
spDoc->QueryInterface(IID_ICustomDoc, (void **)&spCustomDoc);
CComPtr<IDocHostUIHandler> spDocHostUIHandler;
QueryInterface(IID_IDocHostUIHandler, (void **)&spDocHostUIHandler);
spCustomDoc->SetUIHandler(spDocHostUIHandler);
}
原始连接:
http://www.eggheadcafe.com/ng/microsoft.public.inetsdk.programming.mshtml_hosting/post4343696.asp