实现IDocHostShowUI接口

Zark Zark 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
在"定制webbroser控件"(不知翻译是否确切,英文customerized webbrowser control)时, 实现了如下的IDocHostUIHandler接口.
class DocHost : public CComObjectRootEx<CComSingleThreadModel>,
public IDispatchImpl<IDocHostUIHandlerDispatch,
&IID_IDocHostUIHandlerDispatch, &LIBID_ATLLib>
{

DrDebug* m_pLog;
Param* m_pParam;
MainFrame* m_pParent;

CComQIPtr<IDispatch> m_spExternal;

public:

//~ ****************************************************************************
//~ DocHost
//~
//~ Constructor of DocHost class
//~ Parameters:
//~
//~ Return:
//~ ****************************************************************************
DocHost();

//~ ****************************************************************************
//~ ~DocHost
//~
//~ Destructor of DocHost class
//~ Parameters:
//~
//~ Return:
//~ ****************************************************************************
virtual ~DocHost();

BEGIN_COM_MAP(DocHost)
COM_INTERFACE_ENTRY(IDocHostUIHandlerDispatch)
END_COM_MAP()

//~ ****************************************************************************
//~ SetExternal
//~
//~ Set pointer to external object
//~ Parameters:
//~
//~ Return:
//~ ****************************************************************************
void SetExternal(IDispatch* pExt);

//~ ****************************************************************************
//~ SetParent
//~
//~ Set pointer to parent
//~ Parameters:
//~
//~ Return:
//~ ****************************************************************************
BOOL SetParent(MainFrame* pParent);

//~ ****************************************************************************
//~ ShowContextMenu
//~
//~ IDocHostUIHandler Implementation
//~ Parameters:
//~
//~ Return:
//~ ****************************************************************************
HRESULT STDMETHODCALLTYPE ShowContextMenu(DWORD dwID,DWORD x,DWORD y,
IUnknown *pcmdtReserved,IDispatch *pdispReserved,HRESULT *dwRetVal);

//~ ****************************************************************************
//~ GetHostInfo
//~
//~ IDocHostUIHandler Implementation
//~ Parameters:
//~
//~ Return:
//~ ****************************************************************************
HRESULT STDMETHODCALLTYPE GetHostInfo(DWORD* pdwFlags,
DWORD* pdwDoubleClick);

//~ ****************************************************************************
//~ ShowUI
//~
//~ IDocHostUIHandler Implementation
//~ Parameters:
//~
//~ Return:
//~ ****************************************************************************
HRESULT STDMETHODCALLTYPE ShowUI(DWORD dwID,IUnknown *pActiveObject,
IUnknown *pCommandTarget,IUnknown *pFrame,IUnknown *pDoc,
HRESULT *dwRetVal);

//~ ****************************************************************************
//~ HideUI
//~
//~ IDocHostUIHandler Implementation
//~ Parameters:
//~
//~ Return:
//~ ****************************************************************************
HRESULT STDMETHODCALLTYPE HideUI();

//~ ****************************************************************************
//~ UpdateUI
//~
//~ IDocHostUIHandler Implementation
//~ Parameters:
//~
//~ Return:
//~ ****************************************************************************
HRESULT STDMETHODCALLTYPE UpdateUI();

//~ ****************************************************************************
//~ EnableModeless
//~
//~ IDocHostUIHandler Implementation
//~ Parameters:
//~
//~ Return:
//~ ****************************************************************************
HRESULT STDMETHODCALLTYPE EnableModeless(VARIANT_BOOL fEnable);

//~ ****************************************************************************
//~ OnDocWindowActivate
//~
//~ IDocHostUIHandler Implementation
//~ Parameters:
//~
//~ Return:
//~ ****************************************************************************
HRESULT STDMETHODCALLTYPE OnDocWindowActivate(VARIANT_BOOL fActivate);

//~ ****************************************************************************
//~ OnFrameWindowActivate
//~
//~ IDocHostUIHandler Implementation
//~ Parameters:
//~
//~ Return:
//~ ****************************************************************************
HRESULT STDMETHODCALLTYPE OnFrameWindowActivate(VARIANT_BOOL fActivate);

//~ ****************************************************************************
//~ ResizeBorder
//~
//~ IDocHostUIHandler Implementation
//~ Parameters:
//~
//~ Return:
//~ ****************************************************************************
HRESULT STDMETHODCALLTYPE ResizeBorder(long left,long top,long right,
long bottom,IUnknown *pUIWindow,VARIANT_BOOL fFrameWindow);

//~ ****************************************************************************
//~ TranslateAccelerator
//~
//~ IDocHostUIHandler Implementation
//~ Parameters:
//~
//~ Return:
//~ ****************************************************************************
HRESULT STDMETHODCALLTYPE TranslateAccelerator(DWORD_PTR hWnd,DWORD nMessage,
DWORD_PTR wParam,DWORD_PTR lParam,BSTR bstrGuidCmdGroup,DWORD nCmdID,
HRESULT *dwRetVal) ;

//~ ****************************************************************************
//~ GetOptionKeyPath
//~
//~ IDocHostUIHandler Implementation
//~ Parameters:
//~
//~ Return:
//~ ****************************************************************************
HRESULT STDMETHODCALLTYPE GetOptionKeyPath(BSTR *pbstrKey,DWORD dw);

//~ ****************************************************************************
//~ GetDropTarget
//~
//~ IDocHostUIHandler Implementation
//~ Parameters:
//~
//~ Return:
//~ ****************************************************************************
HRESULT STDMETHODCALLTYPE GetDropTarget(IUnknown *pDropTarget,
IUnknown **ppDropTarget);

//~ ****************************************************************************
//~ GetExternal
//~
//~ IDocHostUIHandler Implementation
//~ Parameters:
//~
//~ Return:
//~ ****************************************************************************
HRESULT STDMETHODCALLTYPE GetExternal(IDispatch **ppDispatch);

//~ ****************************************************************************
//~ TranslateUrl
//~
//~ IDocHostUIHandler Implementation
//~ Parameters:
//~
//~ Return:
//~ ****************************************************************************
HRESULT STDMETHODCALLTYPE TranslateUrl(DWORD dwTranslate,BSTR bstrURLIn,
BSTR *pbstrURLOut) ;

//~ ****************************************************************************
//~ FilterDataObject
//~
//~ IDocHostUIHandler Implementation
//~ Parameters:
//~
//~ Return:
//~ ****************************************************************************
HRESULT STDMETHODCALLTYPE FilterDataObject(IUnknown *pDO,IUnknown **ppDORet);

};

在主程序中使用
//- Create CDosHostUIHandelImpl instance
CComObject<DocHost>* pDocHost ;
hr=CComObject<DocHost>::CreateInstance(&pDocHost);
if(FAILED(hr))
{
m_pLog->FormatTrace(_T("Create DocHostUIHandleImpl Failed"));
LEAVE_FUNCTION(m_pLog);
return 0;
}

//- link up with host
CComQIPtr<IDocHostUIHandlerDispatch> pDocHostDisp;
pDocHostDisp=pDocHost;
pHost->SetExternalUIHandler(pDocHostDisp);

(其中pHost的类型是CComPtr<IAxWinHostWindow>)
使webbrowser与IDocHostUIHandler相连, 结果是令人满意的. 现在的问题是: 为了获得javascript中alert()函数事件,必须实现IDocHostShowUI, 请问应如何实现呢?
...全文

相关推荐

MFC编程 14.1 浏览器的定制功能.rar

免责声明:资料部分来源于合法的互联网渠道收集和整理,部分自己学习积累成果,供大家学习参考与交流。收取的费用仅用于收集和整理资料耗费时间的酬劳。 本人尊重原创作者或出版方,资料版权归原作者或出版方所有,本人不对所涉及的版权问题或内容负法律责任。如有侵权,请举报或通知本人删除。

金枝玉叶9

浏览器集成教学 自定义浏览器.docx

浏览器集成教学 自定义浏览器

weixin_41031635

c#制作的扩展浏览器源码

本扩展浏览器以原.net自带的WebBrowser为基类扩展,实现了以下功能: 1、实现了IDocHostShowUI接口,可以截获弹出对话框事件 2、实现了DWebBrowserEvents2接口,可以在本窗口显示弹出窗口 3、实现了其他的一些接口,以实现浏览器的高级功能

sc_ghost

EmbeddedWB_D5-D2010_Version_14.69.0

Embedded Web Browser is a Pack of components that demonstrates an easy way to implement IDocHostUIHandler and IDocHostShowUI with the Webbrowser Control. It includes all the needed components / procedures you will need to build a web browser or a chat client. Including Highlight Html, XML And Full chat Client support. The package contains a demo that contains most of the procedures implementation.

顺欣同创

浏览器扩展 下载图片 源码

chrome浏览器扩展插件编写小例子,将浏览页面的图片全部保存下来,给出的是源代码(可加载使用),可以自行再修改或利用。代码中还有一小部分url地址串的分析、browserAction.setBadgeText图标标识文字的简单利用

wtg286
评论 12
收藏 已收藏
分享
返回顶部
Zark
ATL 3,248 成员 48,530 内容