IDocHostUIHandler是IE暴露的一个不完全的界面取代接口,通过ICstomDoc的设置来确定IE界面的显示结果。
要点主要如下:
1。首先引入:ICustomDoc的头Mshtmhst.h(如若没有:一直提示找不到ICustomDoc标示符)
class TDocHostUIHandlerImpl : public IDocHostUIHandler
2。继承自IDocHostUIHandler的接口需要进行实例化后设置为ICustomDoc的宿主,否则提示错误。
hr1 = ICu-> SetUIHandler(FDocHostUIHandler);
3。头部实现接口的方法,cpp中实现方法的过程。
.h:
HRESULT __stdcall QueryInterface(REFIID riid, void **ppv);
ULONG __stdcall AddRef();
ULONG __stdcall Release();
.cpp:
STDMETHODIMP TDocHostUIHandlerImpl::ShowContextMenu(DWORD dwID,POINT *ppt,
IUnknown *pcmdtReserved,IDispatch *pdispReserved)
{
MessageBox(NULL,_T("ShowContextMenu ID = ") ,
NULL,MB_OK | MB_APPLMODAL | MB_ICONWARNING);
return S_OK;
}
// IDocHostUIHandler Method
STDMETHOD(ShowContextMenu)(
/* [in] */ DWORD dwID,
/* [in] */ POINT __RPC_FAR *ppt,
/* [in] */ IUnknown __RPC_FAR *pcmdtReserved,
/* [in] */ IDispatch __RPC_FAR *pdispReserved);
以上步骤实现即可顺利改变界面。
以下是方法功能:
Method | Description |
---|---|
IDocHostUIHandler::EnableModeless | Called by the MSHTML implementation of IOleInPlaceActiveObject::EnableModeless. Also called when MSHTMLdisplays a modal UI. |
IDocHostUIHandler::FilterDataObject | Enables the host to replace the MSHTML data object. |
IDocHostUIHandler::GetDropTarget | Enables the host to supply an alternative IDropTarget interface. |
IDocHostUIHandler::GetExternal | Gets the host's IDispatch interface. |
IDocHostUIHandler::GetHostInfo | Gets the UI capabilities of the application that is hosting MSHTML. |
IDocHostUIHandler::GetOptionKeyPath | Gets a registry subkey path that overrides the default Internet Explorer registry settings. |
IDocHostUIHandler::HideUI | Enables the host to remove its menus and toolbars. |
IDocHostUIHandler::OnDocWindowActivate | Called by the MSHTML implementation of IOleInPlaceActiveObject::OnDocWindowActivate. |
IDocHostUIHandler::OnFrameWindowActivate | Called by the MSHTML implementation of IOleInPlaceActiveObject::OnFrameWindowActivate. |
IDocHostUIHandler::ResizeBorder | Called by the MSHTML implementation of IOleInPlaceActiveObject::ResizeBorder. |
IDocHostUIHandler::ShowContextMenu | Enables MSHTML to display a shortcut menu. |
IDocHostUIHandler::ShowUI | Enables the host to replace MSHTML menus and toolbars. |
IDocHostUIHandler::TranslateAccelerator | Called by MSHTML when IOleInPlaceActiveObject::TranslateAccelerator or IOleControlSite::TranslateAccelerator is called. |
IDocHostUIHandler::TranslateUrl | Enables the host to modify the URL to be loaded. |
IDocHostUIHandler::UpdateUI | Notifies the host that the command state has changed. |