📄 contextmenusample.cpp
字号:
// ContextMenuSample.cpp : implementation file
//
#include "stdafx.h"
#include "CMS.h"
#include "ContextMenuSample.h"
#include "Commacros.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//
#define ResultFromShort(i) ResultFromScode(MAKE_SCODE(SEVERITY_SUCCESS, 0, (USHORT)(i)))
/////////////////////////////////////////////////////////////////////////////
// CContextMenuSample
IMPLEMENT_DYNCREATE(CContextMenuSample, CCmdTarget)
CContextMenuSample::CContextMenuSample()
{
EnableAutomation();
}
CContextMenuSample::~CContextMenuSample()
{
}
void CContextMenuSample::OnFinalRelease()
{
// When the last reference for an automation object is released
// OnFinalRelease is called. The base class will automatically
// deletes the object. Add additional cleanup required for your
// object before calling the base class.
CCmdTarget::OnFinalRelease();
}
BEGIN_MESSAGE_MAP(CContextMenuSample, CCmdTarget)
//{{AFX_MSG_MAP(CContextMenuSample)
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
BEGIN_DISPATCH_MAP(CContextMenuSample, CCmdTarget)
//{{AFX_DISPATCH_MAP(CContextMenuSample)
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_DISPATCH_MAP
END_DISPATCH_MAP()
// Note: we add support for IID_IContextMenuSample to support typesafe binding
// from VBA. This IID must match the GUID that is attached to the
// dispinterface in the .ODL file.
//
// {5F5F7E70-ADC6-11D3-AF23-AC9F5AA57808}
static const IID IID_IContextMenuSample =
{ 0x5f5f7e70, 0xadc6, 0x11d3, { 0xaf, 0x23, 0xac, 0x9f, 0x5a, 0xa5, 0x78, 0x8 } };
//IMPLEMENT_OLECREATE宏,可自动实现类对象实例化
IMPLEMENT_OLECREATE(CContextMenuSample,"ContextMenuSample", 0x5f5f7e70, 0xadc6, 0x11d3, 0xaf, 0x23, 0xac, 0x9f, 0x5a, 0xa5, 0x78, 0x8 )
//实现接口映射
BEGIN_INTERFACE_MAP(CContextMenuSample, CCmdTarget)
//IContextMenu 接口
INTERFACE_PART(CContextMenuSample, IID_IContextMenu, CMS)
//IShellExtInit 接口
INTERFACE_PART(CContextMenuSample, IID_IShellExtInit, SEI)
END_INTERFACE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CContextMenuSample message handlers
//IShellExtInit接口的实现
//IMPLEMENT_IUNKNOWN实现了IUnknown接口的基本方法,请参阅Commacros.h文件
IMPLEMENT_IUNKNOWN(CContextMenuSample,SEI)
STDMETHODIMP CContextMenuSample::XSEI::Initialize(LPCITEMIDLIST pidlFolder,
LPDATAOBJECT lpdobj,
HKEY hkeyProgID)
{
//METHOD_PROLOGUE 宏用于建立名叫pThis的局部变量,该变量是指向接口函数表的指针。
//该宏必须置于每个接口实现之前。
METHOD_PROLOGUE(CContextMenuSample,SEI);
return (HRESULT)NOERROR;
}
//IMPLEMENT_IUNKNOWN实现了IUnknown接口的基本方法,请参阅Commacros.h文件
IMPLEMENT_IUNKNOWN(CContextMenuSample,CMS)
STDMETHODIMP CContextMenuSample::XCMS::QueryContextMenu(
HMENU hmenu,
UINT indexMenu,
UINT idCmdFirst,
UINT idCmdLast,
UINT uFlags)
{
METHOD_PROLOGUE(CContextMenuSample,CMS);
UINT idCmd = idCmdFirst;
//在上下文菜单中添加菜单选项
InsertMenu(hmenu,indexMenu,MF_STRING|MF_BYPOSITION,idCmd++,"CMS Sample");
//得到位图
HBITMAP hBmp = LoadBitmap(AfxGetApp()->m_hInstance, MAKEINTRESOURCE(IDB_BMP));
//在菜单旁设置位图
SetMenuItemBitmaps(hmenu, indexMenu, MF_BYPOSITION, hBmp, hBmp);
return ResultFromShort(idCmd - idCmdFirst);
}
STDMETHODIMP CContextMenuSample::XCMS::InvokeCommand(LPCMINVOKECOMMANDINFO lpici)
{
METHOD_PROLOGUE(CContextMenuSample,CMS);
//检测菜单项是否被选中
if (!HIWORD(lpici->lpVerb))
{
UINT idCmd = LOWORD(lpici->lpVerb);
if(idCmd==0)
AfxMessageBox("ContextMenu Sample !");
}
return (HRESULT)NOERROR;
}
STDMETHODIMP CContextMenuSample::XCMS::GetCommandString(
UINT idCmd,
UINT uType,
UINT * pwReserved,
LPSTR pszName,
UINT cchMax)
{
METHOD_PROLOGUE(CContextMenuSample,CMS);
return (HRESULT)NOERROR;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -