首页 热点资讯 义务教育 高等教育 出国留学 考研考公

如何禁用对 visualc++ 中 chtmlview 默认弹出式菜单

发布网友 发布时间:2022-04-22 18:24

我来回答

1个回答

热心网友 时间:2023-10-24 13:56

1. 创建应用程序向导生成的 sdi 应用程序调用 mysample。 在步骤 6 / 6 更改到 chtmlview。
2. 打开 mysample.h 并如下所示到 cmysampleapp 类添加公共成员变量: public:
class cimpidispatch* m_pdispom;

3. 向项目称为 " custsite.h " 添加新头文件。 以下代码复制并粘贴到它: //=--------------------------------------------------------------------------=
// (c) copyright 1996-1999 microsoft corporation. all rights reserved.
//=--------------------------------------------------------------------------=
#ifndef __customsiteh__
#define __customsiteh__
#include "idispimp.h"
#include <mshtmhst.h>
//
// note:
// some of the code in this file is mfc implementation specific.
// changes in future versions of mfc implementation may require
// the code to be changed. please check the readme of this
// sample for more information
//
class ccustomcontrolsite:public colecontrolsite
{
public:
ccustomcontrolsite(colecontrolcontainer *pcnt):colecontrolsite(pcnt){}
protected:
declare_interface_map();
begin_interface_part(dochostuihandler, idochostuihandler)
stdmethod(showcontextmenu)(/* [in] */ dword dwid,
/* [in] */ point __rpc_far *ppt,
/* [in] */ iunknown __rpc_far *pcmdtreserved,
/* [in] */ idispatch __rpc_far *pdispreserved);
stdmethod(gethostinfo)(
/* [out][in] */ dochostuiinfo __rpc_far *pinfo);
stdmethod(showui)(
/* [in] */ dword dwid,
/* [in] */ ioleinplaceactiveobject __rpc_far *pactiveobject,
/* [in] */ iolecommandtarget __rpc_far *pcommandtarget,
/* [in] */ ioleinplaceframe __rpc_far *pframe,
/* [in] */ ioleinplaceuiwindow __rpc_far *pdoc);
stdmethod(hideui)(void);
stdmethod(updateui)(void);
stdmethod(enablemodeless)(/* [in] */ bool fenable);
stdmethod(ondocwindowactivate)(/* [in] */ bool fenable);
stdmethod(onframewindowactivate)(/* [in] */ bool fenable);
stdmethod(resizeborder)(
/* [in] */ lpcrect prcborder,
/* [in] */ ioleinplaceuiwindow __rpc_far *puiwindow,
/* [in] */ bool framewindow);
stdmethod(translateaccelerator)(
/* [in] */ lpmsg lpmsg,
/* [in] */ const guid __rpc_far *pguidcmdgroup,
/* [in] */ dword ncmdid);
stdmethod(getoptionkeypath)(
/* [out] */ lpolestr __rpc_far *pchkey,
/* [in] */ dword dw);
stdmethod(getdroptarget)(
/* [in] */ idroptarget __rpc_far *pdroptarget,
/* [out] */ idroptarget __rpc_far *__rpc_far *ppdroptarget);
stdmethod(getexternal)(
/* [out] */ idispatch __rpc_far *__rpc_far *ppdispatch);
stdmethod(translateurl)(
/* [in] */ dword dwtranslate,
/* [in] */ olechar __rpc_far *pchurlin,
/* [out] */ olechar __rpc_far *__rpc_far *ppchurlout);
stdmethod(filterdataobject)(
/* [in] */ idataobject __rpc_far *pdo,
/* [out] */ idataobject __rpc_far *__rpc_far *ppdoret);
end_interface_part(dochostuihandler)
};
class ccustomoccmanager :public coccmanager
{
public:
ccustomoccmanager(){}
colecontrolsite* createsite(colecontrolcontainer* pctrlcont)
{
ccustomcontrolsite *psite = new ccustomcontrolsite(pctrlcont);
return psite;
}
};
#endif

4. 添加新 cpp 文件称为 " custsite.cpp " 并添加到下面代码: //=--------------------------------------------------------------------------=
// (c) copyright 1996-1999 microsoft corporation. all rights reserved.
//=--------------------------------------------------------------------------=
//
// note:
// some of the code in this file is mfc implementation specific.
// changes in future versions of mfc implementation may require
// the code to be changed. please check the readme of this
// sample for more information
//
#include "stdafx.h"
#undef afx_data
#define afx_data afx_data_import
#include "mysample.h"
// note: this line is a hardcoded reference to an mfc header file
// this path may need to be changed to refer to the location of vc5 install
// for successful compilation.
#include <..srcoccimpl.h>
#undef afx_data
#define afx_data afx_data_export
#include "custsite.h"
begin_interface_map(ccustomcontrolsite, colecontrolsite)
interface_part(ccustomcontrolsite, iid_idochostuihandler, dochostuihandler)
end_interface_map()

ulong far export ccustomcontrolsite::xdochostuihandler::addref()
{
method_prologue(ccustomcontrolsite, dochostuihandler)
return pthis->externaladdref();
}
ulong far export ccustomcontrolsite::xdochostuihandler::release()
{
method_prologue(ccustomcontrolsite, dochostuihandler)
return pthis->externalrelease();
}
hresult far export ccustomcontrolsite::xdochostuihandler::queryinterface(refiid riid, void **ppvobj)
{
method_prologue(ccustomcontrolsite, dochostuihandler)
hresult hr = (hresult)pthis->externalqueryinterface(&riid, ppvobj);
return hr;
}
// * cimpidochostuihandler::gethostinfo
// *
// * purpose: called at initialization
// *
hresult far export ccustomcontrolsite::xdochostuihandler::gethostinfo( dochostuiinfo* pinfo )
{
method_prologue(ccustomcontrolsite, dochostuihandler)
pinfo->dwflags = dochostuiflag_no3dborder;
pinfo->dwdoubleclick = dochostuidblclk_default;
return s_ok;
}
// * cimpidochostuihandler::showui
// *
// * purpose: called when mshtml.dll shows its ui
// *
hresult far export ccustomcontrolsite::xdochostuihandler::showui(
dword dwid,
ioleinplaceactiveobject * /*pactiveobject*/,
iolecommandtarget * pcommandtarget,
ioleinplaceframe * /*pframe*/,
ioleinplaceuiwindow * /*pdoc*/)
{
method_prologue(ccustomcontrolsite, dochostuihandler)
// we've already got our own ui in place so just return s_ok
return s_ok;
}
// * cimpidochostuihandler::hideui
// *
// * purpose: called when mshtml.dll hides its ui
// *
hresult far export ccustomcontrolsite::xdochostuihandler::hideui(void)
{
method_prologue(ccustomcontrolsite, dochostuihandler)
return s_ok;
}
// * cimpidochostuihandler::updateui
// *
// * purpose: called when mshtml.dll updates its ui
// *
hresult far export ccustomcontrolsite::xdochostuihandler::updateui(void)
{
method_prologue(ccustomcontrolsite, dochostuihandler)
// mfc is pretty good about updating it's ui in it's idle loop so i don't do anything here
return s_ok;
}
// * cimpidochostuihandler::enablemodeless
// *
// * purpose: called from mshtml.dll's ioleinplaceactiveobject::enablemodeless
// *
hresult far export ccustomcontrolsite::xdochostuihandler::enablemodeless(bool /*fenable*/)
{
method_prologue(ccustomcontrolsite, dochostuihandler)
return e_notimpl;
}
// * cimpidochostuihandler::ondocwindowactivate
// *
// * purpose: called from mshtml.dll's ioleinplaceactiveobject::ondocwindowactivate
// *
hresult far export ccustomcontrolsite::xdochostuihandler::ondocwindowactivate(bool /*factivate*/)
{
method_prologue(ccustomcontrolsite, dochostuihandler)
return e_notimpl;
}
// * cimpidochostuihandler::onframewindowactivate
// *
// * purpose: called from mshtml.dll's ioleinplaceactiveobject::onframewindowactivate
// *
hresult far export ccustomcontrolsite::xdochostuihandler::onframewindowactivate(bool /*factivate*/)
{
method_prologue(ccustomcontrolsite, dochostuihandler)
return e_notimpl;
}
// * cimpidochostuihandler::resizeborder
// *
// * purpose: called from mshtml.dll's ioleinplaceactiveobject::resizeborder
// *
hresult far export ccustomcontrolsite::xdochostuihandler::resizeborder(
lpcrect /*prcborder*/,
ioleinplaceuiwindow* /*puiwindow*/,
bool /*framewindow*/)
{
method_prologue(ccustomcontrolsite, dochostuihandler)
return e_notimpl;
}
// * cimpidochostuihandler::showcontextmenu
// *
// * purpose: called when mshtml.dll would normally display its context menu
// *
hresult far export ccustomcontrolsite::xdochostuihandler::showcontextmenu(
dword /*dwid*/,
point* /*pptposition*/,
iunknown* /*pcommandtarget*/,
idispatch* /*pdispatchobjecthit*/)
{
method_prologue(ccustomcontrolsite, dochostuihandler)
return s_ok; // we've shown our own context menu. mshtml.dll will no longer try to show its own.
}
// * cimpidochostuihandler::translateaccelerator
// *
// * purpose: called from mshtml.dll's translateaccelerator routines
// *
hresult far export ccustomcontrolsite::xdochostuihandler::translateaccelerator(lpmsg lpmsg,
/* [in] */ const guid __rpc_far *pguidcmdgroup,
/* [in] */ dword ncmdid)
{
method_prologue(ccustomcontrolsite, dochostuihandler)
return s_false;
}
// * cimpidochostuihandler::getoptionkeypath
// *
// * purpose: called by mshtml.dll to find where the host wishes to store
// * its options in the registry
// *
hresult far export ccustomcontrolsite::xdochostuihandler::getoptionkeypath(bstr* pbstrkey, dword)
{
method_prologue(ccustomcontrolsite, dochostuihandler)
return e_notimpl;
}
stdmethodimp ccustomcontrolsite::xdochostuihandler::getdroptarget(
/* [in] */ idroptarget __rpc_far *pdroptarget,
/* [out] */ idroptarget __rpc_far *__rpc_far *ppdroptarget)
{
method_prologue(ccustomcontrolsite, dochostuihandler)
return e_notimpl;
}
stdmethodimp ccustomcontrolsite::xdochostuihandler::getexternal(
/* [out] */ idispatch __rpc_far *__rpc_far *ppdispatch)
{
// return the idispatch we have for extending the object model
idispatch* pdisp = (idispatch*)theapp.m_pdispom;
pdisp->addref();
*ppdispatch = pdisp;
return s_ok;
}

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com