自己做的浏览器,如何屏蔽掉右键弹出菜单,烦劳各位高手了!
解决方案 »
- 将一个.c文件变成.cpp后,编译时出现如下错误。。。。
- 请教如何将ListBox控件中每行文本设成水平和垂直居中方式啊!!
- 如何得到CEdit控件在其父窗口的CRect?
- 推荐一个暴好的数据库Berkeley DB。
- 如果你是高手,想找份工作,进来写上你的资料和作品~~
- 关于基于对话框的消息映射问题!
- 核心编程上说的挂接api的方法,我试了怎么不行?哪位有成功经验的介绍一下!
- release F5运行与Ctrl+F5运行不一样
- 紧急求助!如何统计不重复记录的总数在ACCESS中?
- 在MSDN中, CListCtrl::SortItems 有个例子,其中有很多不懂,请各位大侠解释????
- 为什么每次都要重新编译?每次build就和rebuild效果一样!哪儿设置有问题?请指教!
- 写一个支持MFC的ATL COM 但是编译时出错!!:(
要将ie的那个讨的厌的弹出式菜单去掉,可不是件容易的事,可能很多的程序员都作过尝试,显然地,捕获wm_rbuttondown,wm_rbuttonup,wm_contextmenu,消息以及重载pretranslatemessage等方法,都不能取得很好的结果。
这一切都与ie的扩展接口idochostuihandler有关,在此并不想对此接口作详细讲述,只针此我们的需求--去掉弹出式菜单,用一个例子作为注解。
第一、实现chtmlctrl。
chtmlctrl这个类是对话框中使用chtmlview显示网页的必备。其实很简单,只要注意以下几点就行:
1.从chtmlview派生。
2.构造函数必需public,因为chtmlview的构造函数是protect的。
3.捕获wm_mouseactivate消息,如下:
int chtmlctrl::onmouseactivate(cwnd* pdesktopwnd, uint nhittest, uint message)
{
return cwnd::onmouseactivate(pdesktopwnd, nhittest, message);
^^^^ 注意:不是chtmlview
}
4.重载postncdestroy,并且什么也不做。
ok,没问题了,你现在可以在对话框中声明chtmlctrl变量,并且create,navigate,现在网页显示出来了,下一步。
第二、写一个奇怪的,有点像com类对象的一个c++类(cmyui)。
#include <mshtmhst.h>
class cmyui:public idochostuihandler
{
public:
bool m_vbenablectxmenus;
cmyui():m_vbenablectxmenus(false){} // false 表示不显示弹出式菜单
virtual ~cmyui(){} stdmethod(showcontextmenu)(dword dwid, point far* ppt, iunknown far* pcmdtreserved,
idispatch far* pdispreserved) {
if (m_vbenablectxmenus == true) // show context menu
return s_false;
else
return s_ok;
}
stdmethod(gethostinfo)(dochostuiinfo far *pinfo) {
return e_notimpl;
}
stdmethod(showui)(dword dwid, ioleinplaceactiveobject far* pactiveobject,
iolecommandtarget far* pcommandtarget,
ioleinplaceframe far* pframe,
ioleinplaceuiwindow far* pdoc) {
return e_notimpl;
}
stdmethod(hideui)(void) {
return e_notimpl;
}
stdmethod(updateui)(void) {
return e_notimpl;
}
stdmethod(enablemodeless)(bool fenable) {
return e_notimpl;
}
stdmethod(ondocwindowactivate)(bool factivate) {
return e_notimpl;
}
stdmethod(onframewindowactivate)(bool factivate) {
return e_notimpl;
}
stdmethod(resizeborder)(lpcrect prcborder, ioleinplaceuiwindow far* puiwindow,
bool framewindow) {
return e_notimpl;
}
stdmethod(translateaccelerator)(lpmsg lpmsg, const guid far* pguidcmdgroup,
dword ncmdid) { return e_notimpl;
}
stdmethod(getoptionkeypath)(lpolestr far* pchkey, dword dw) {
return e_notimpl;
}
stdmethod(getdroptarget)(idroptarget* pdroptarget,
idroptarget** ppdroptarget) {
return e_notimpl;
}
stdmethod(getexternal)(idispatch** ppdispatch) {
return e_notimpl;
}
stdmethod(translateurl)(dword dwtranslate, olechar* pchurlin,
olechar** ppchurlout) {
return e_notimpl;
}
stdmethod(filterdataobject)(idataobject* pdo, idataobject** ppdoret) {
return e_notimpl;
}
stdmethodimp queryinterface(refiid iid, lpvoid* ppvobj){
if (iid == iid_iunknown || iid == iid_idochostuihandler) {
*ppvobj = this;
return s_ok;
}
return s_false;
}
stdmethodimp_(ulong) addref(){
return 1;
}
stdmethodimp_(ulong) release(){
return 1;
}
};
这个类主要实现了一个idochostuihandler,由于并不是一个真正的com类对象,所以不用实现com的其它内容。这一步的工作也很简单,不是吗?当然,要知道为什么,你得去看看msdn上关于idochostuihandler的内容。
第三、拼在一起。
1.在上面实现的chtmlctrl加入公有成员idochostuihandler* m_ui。
2.在chtmlctrl的构造函数中加入
cmyui* t = new cmyui;
t->queryinterface(iid_idochostuihandler, (void**)&m_ui);
3.重载onnavigatecomplete2,加入以下代码:
{
chtmlview::onnavigatecomplete2(strurl);
idispatch* pdoc = gethtmldocument();
if (pdoc == null) {
pdoc->release();
return;
}
icustomdoc* pdoc2=null;
hresult hresult = pdoc->queryinterface(iid_icustomdoc, (void**)&pdoc2);
if (failed(hresult)) {
pdoc->release();
return;
}
pdoc->release();
pdoc2->setuihandler(m_ui);
pdoc2->release();
}
大功告成