博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ATL使用IE控件,并且屏蔽右键
阅读量:6307 次
发布时间:2019-06-22

本文共 3678 字,大约阅读时间需要 12 分钟。

首先先实现IDocHostUIHandlerDispatch接口

--------------------------------------------------------------------------------------------

class ATL_NO_VTABLE CMyUIHandler : 	public CComObjectRootEx
, public CComCoClass
, public IDispatchImpl
{public: CComQIPtr
m_spExtDispatch;public: CMyUIHandler() { }DECLARE_PROTECT_FINAL_CONSTRUCT()BEGIN_COM_MAP(CMyUIHandler) COM_INTERFACE_ENTRY(IDocHostUIHandlerDispatch) COM_INTERFACE_ENTRY(IDispatch)END_COM_MAP()// IXmnWrapperUIHandlerpublic: // Do not show the context menu STDMETHOD (ShowContextMenu) ( /* [in] */ DWORD dwID, /* [in] */ DWORD x, /* [in] */ DWORD y, /* [in] */ IUnknown *pcmdtReserved, /* [in] */ IDispatch *pdispReserved, /* [retval][out] */ HRESULT *dwRetVal) { *dwRetVal = S_OK; return S_OK; } // Mark all the other methods as not implemented STDMETHOD (GetHostInfo) ( /* [out][in] */ DWORD *pdwFlags, /* [out][in] */ DWORD *pdwDoubleClick) { return E_NOTIMPL; } STDMETHOD (ShowUI) ( /* [in] */ DWORD dwID, /* [in] */ IUnknown *pActiveObject, /* [in] */ IUnknown *pCommandTarget, /* [in] */ IUnknown *pFrame, /* [in] */ IUnknown *pDoc, /* [retval][out] */ HRESULT *dwRetVal) { return E_NOTIMPL; } STDMETHOD (HideUI) (void) { return E_NOTIMPL; } STDMETHOD (UpdateUI) (void) { return E_NOTIMPL; } STDMETHOD (EnableModeless) ( /* [in] */ VARIANT_BOOL fEnable) { return E_NOTIMPL; } STDMETHOD (OnDocWindowActivate) ( /* [in] */ VARIANT_BOOL fActivate) { return E_NOTIMPL; } STDMETHOD (OnFrameWindowActivate) ( /* [in] */ VARIANT_BOOL fActivate) { return E_NOTIMPL; } STDMETHOD (ResizeBorder) ( /* [in] */ long left, /* [in] */ long top, /* [in] */ long right, /* [in] */ long bottom, /* [in] */ IUnknown *pUIWindow, /* [in] */ VARIANT_BOOL fFrameWindow) { return E_NOTIMPL; } STDMETHOD (TranslateAccelerator) ( /* [in] */ DWORD hWnd, /* [in] */ DWORD nMessage, /* [in] */ DWORD wParam, /* [in] */ DWORD lParam, /* [in] */ BSTR bstrGuidCmdGroup, /* [in] */ DWORD nCmdID, /* [retval][out] */ HRESULT *dwRetVal) { return E_NOTIMPL; } STDMETHOD (GetOptionKeyPath) ( /* [out] */ BSTR *pbstrKey, /* [in] */ DWORD dw) { return E_NOTIMPL; } STDMETHOD (GetDropTarget) ( /* [in] */ IUnknown *pDropTarget, /* [out] */ IUnknown **ppDropTarget) { return E_NOTIMPL; } STDMETHOD (GetExternal) ( /* [out] */ IDispatch **ppDispatch) { return m_spExtDispatch.CopyTo (ppDispatch); } STDMETHOD (TranslateUrl) ( /* [in] */ DWORD dwTranslate, /* [in] */ BSTR bstrURLIn, /* [out] */ BSTR *pbstrURLOut) { return E_NOTIMPL; } STDMETHOD (FilterDataObject) ( /* [in] */ IUnknown *pDO, /* [out] */ IUnknown **ppDORet) { return E_NOTIMPL; }};

--------------------------------------------------------------------------------------------

然后通过SetExternalUIHandler将IDocHostUIHandlerDispatch指针传进CAxHostWindow

CComPtr
punkCtrl; CComQIPtr
pWB2; CComVariant v; CRect rc(0,0,640,480); m_wndIE.Create ( *this, rc, _T(""), WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN, WS_EX_CLIENTEDGE ); //m_wndIE.CreateControlEx ( L"{8856F961-340A-11D0-A96B-00C04FD705A2}", NULL, // NULL, &punkCtrl ); m_wndIE.CreateControlEx ( L"Shell.Explorer", NULL, NULL, &punkCtrl ); pWB2 = punkCtrl; if ( pWB2 ) pWB2->Navigate ( CComBSTR("http://www.microsoft.com"), &v, &v, &v, &v ); CComPtr
spUnk; HRESULT hr = CMyUIHandler::_CreatorClass::CreateInstance(NULL, IID_IUnknown, (void**)&spUnk); ATLASSERT(SUCCEEDED(hr)); CComQIPtr
spUI = spUnk; m_wndIE.SetExternalUIHandler(spUI);

转载于:https://www.cnblogs.com/fanzi2009/archive/2010/05/07/1729961.html

你可能感兴趣的文章
邮箱注册代码
查看>>
Double数据保留位数的方法
查看>>
sqlite数据库执行full outer join
查看>>
2015-01-29
查看>>
2016-01-26
查看>>
Thymeleaf 模板 在spring boot 中的引用和应用
查看>>
Java学习笔记二十三:Java的继承初始化顺序
查看>>
oracle的nvl()函数的用法
查看>>
宏定义函数的易错点
查看>>
洛谷【P2458】[SDOI2006]保安站岗 题解 树上DP
查看>>
Shredding Company 碎纸机,dfs()枚举每一种情况,再加剪枝。
查看>>
命名空间和模块化编程 - C++快速入门39
查看>>
结构化程序设计03 - 零基础入门学习Delphi12
查看>>
今天才知道怎么插入代码!!!!!!!!!
查看>>
D2007在64位Win7出现 delphi 2007 assertion failure thread32.cpp 的解决办法
查看>>
STM32的TAMPER-RTC管脚作为Tamper的使用[转]
查看>>
[记]一个逐步“优化”的范例程序
查看>>
2012-01-09_2
查看>>
Visual Studio 2015 开发MVC4出现错误
查看>>
MongoDB 学习笔记之 批处理
查看>>