📄 cshellext.cpp
字号:
//////////////////////////////////////////////////////////////////////////////
// CShellExt.cpp
//
// Definition of class CShellExt.
//////////////////////////////////////////////////////////////////////////////
// $Id: CShellExt.cpp,v 1.3 1998/12/14 19:00:43 nryan Exp $
// Copyright (C) 1998 by Network Associates, Inc.
// All rights reserved.
#include "StdAfx.h"
#include "Required.h"
#include "DriverComm.h"
#include "DualErr.h"
#include "PGPdiskRegistry.h"
#include "StringAssociation.h"
#include "UtilityFunctions.h"
#include "Win32Utils.h"
#include "WindowsVersion.h"
#include "CShellExt.h"
#include "Globals.h"
////////////
// Constants
////////////
static LPCSTR kPGPdiskShellExtSendToStringNT = "Send &To";
static LPCSTR kPGPdiskShellExtSendToStringWin95 = "Se&nd To";
/////////
// Macros
/////////
#define ResultFromShort(i) ResultFromScode(MAKE_SCODE(SEVERITY_SUCCESS, \
0, (USHORT)(i)))
//////////////////////////////////////////
// Class CShellExt public member functions
//////////////////////////////////////////
// The CShellExt default constructor.
CShellExt::CShellExt()
{
mPDataObj = NULL;
mRefCount = 0;
mTargets = NULL;
mNumDropped = 0;
mNumTotalPGPdisks = 0;
mNumMountedPGPdisks = 0;
DLL->mGCRefThisDll++;
}
// The CShellExt destructor.
CShellExt::~CShellExt()
{
DeletePathsAndCommandLine();
DLL->mGCRefThisDll--;
}
// QueryInterface returns a pointer to this class object's interface.
STDMETHODIMP
CShellExt::QueryInterface(REFIID riid, LPVOID FAR *ppv)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
(* ppv) = NULL;
if (IsEqualIID(riid, IID_IShellExtInit) ||
IsEqualIID(riid, IID_IUnknown))
{
(* ppv) = (LPSHELLEXTINIT) this;
}
else if (IsEqualIID(riid, IID_IContextMenu))
{
(* ppv) = (LPCONTEXTMENU) this;
}
if (* ppv)
{
AddRef();
return NOERROR;
}
else
{
return E_NOINTERFACE;
}
}
// QueryContextMenu is called to construct our context menu.
STDMETHODIMP
CShellExt::QueryContextMenu(
HMENU hMenu,
UINT indexMenu,
UINT idCmdFirst,
UINT idCmdLast,
UINT uFlags)
{
DualErr derr;
PGPBoolean hasTimedOut, success;
PGPUInt32 itemPosition, menuId, subMenuPosition;
AFX_MANAGE_STATE(AfxGetStaticModuleState());
menuId = idCmdFirst;
itemPosition = 0;
hasTimedOut = FALSE;
// Shift key down?
mShiftKeyDown = (::GetAsyncKeyState(VK_SHIFT) & 0x8000 ? TRUE : FALSE);
// Beta or demo timed out?
#if PGPDISK_BETAVERSION
hasTimedOut = HasBetaTimedOut();
#elif PGPDISK_DEMOVERSION
hasTimedOut = HasDemoTimedOut();
#endif // PGPDISK_BETAVERSION
// Only show a menu if we found PGPdisks.
if (mNumTotalPGPdisks == 0)
derr = DualErr(kPGDMinorError_FailSilently);
// There are also other special cases in which we don't show the menu.
if (derr.IsntError())
{
if (((uFlags & 0x000F) != CMF_NORMAL) &&
!(uFlags & CMF_EXPLORE) && !(uFlags & CMF_VERBSONLY))
{
derr = DualErr(kPGDMinorError_FailSilently);
}
}
// Save parent menu handle for later.
if (derr.IsntError())
{
if (!mParentMenu.Attach(hMenu))
derr = DualErr(kPGDMinorError_AttachMenuFailed);
}
// Create the submenu.
if (derr.IsntError())
{
if (!mSubMenu.CreatePopupMenu())
derr = DualErr(kPGDMinorError_CreatePopupMenuFailed);
}
// Add items to the menu.
if (derr.IsntError())
{
PGPUInt32 flags, sendToPosition;
flags = MF_BYPOSITION;
// Insert open/mount/unmount item.
if (mNumTotalPGPdisks > 1)
{
mSubMenu.InsertMenu(itemPosition++, flags, menuId++,
GetCommonString(kPGPdiskShellExtOpenMenuString));
}
else if (mNumMountedPGPdisks == 1)
{
mSubMenu.InsertMenu(itemPosition++, flags, menuId++,
GetCommonString(kPGPdiskShellExtUnmountMenuString));
}
else
{
mSubMenu.InsertMenu(itemPosition++, flags, menuId++,
GetCommonString(kPGPdiskShellExtMountMenuString));
}
// Insert separator.
mSubMenu.InsertMenu(itemPosition++, flags | MF_SEPARATOR, 0);
// Insert passphrase items.
flags = MF_BYPOSITION | (mNumMountedPGPdisks > 0 ? MF_GRAYED : NULL);
mSubMenu.InsertMenu(itemPosition++, flags, menuId++,
GetCommonString(kPGPdiskShellExtAddPassMenuString));
mSubMenu.InsertMenu(itemPosition++, flags, menuId++,
GetCommonString(kPGPdiskShellExtChangePassMenuString));
if (mShiftKeyDown)
{
mSubMenu.InsertMenu(itemPosition++, flags, menuId++,
GetCommonString(kPGPdiskShellExtRemoveAltsMenuString));
}
else
{
mSubMenu.InsertMenu(itemPosition++, flags, menuId++,
GetCommonString(kPGPdiskShellExtRemovePassMenuString));
}
mSubMenu.InsertMenu(itemPosition++, flags, menuId++,
GetCommonString(kPGPdiskShellExtPubKeysMenuString));
// Insert separator.
flags = MF_BYPOSITION | MF_SEPARATOR;
mSubMenu.InsertMenu(itemPosition++, flags | MF_SEPARATOR, 0);
// Insert help item.
flags = MF_BYPOSITION;
mSubMenu.InsertMenu(itemPosition++, flags, menuId++,
GetCommonString(kPGPdiskShellExtHelpMenuString));
// Find position of "Send To".
if (IsWin95CompatibleMachine())
{
sendToPosition = FindMenuItemPosition(&mParentMenu,
kPGPdiskShellExtSendToStringWin95);
}
else
{
sendToPosition = FindMenuItemPosition(&mParentMenu,
kPGPdiskShellExtSendToStringNT);
}
if (sendToPosition == -1)
subMenuPosition = indexMenu;
else
subMenuPosition = sendToPosition + 1;
// Insert another separator.
mParentMenu.InsertMenu(subMenuPosition++,
MF_BYPOSITION | MF_SEPARATOR, 0);
// Insert the submenu menu.
success = mParentMenu.InsertMenu(subMenuPosition,
MF_BYPOSITION | MF_POPUP, (PGPUInt32) mSubMenu.m_hMenu,
"&PGPdisk");
if (!success)
derr = DualErr(kPGDMinorError_InsertMenuFailed);
}
return ResultFromShort(itemPosition);
}
// InvokeCommand is called after the user has selected a menu item.
STDMETHODIMP
CShellExt::InvokeCommand(LPCMINVOKECOMMANDINFO lpcmi)
{
HRESULT hr = E_INVALIDARG;
AFX_MANAGE_STATE(AfxGetStaticModuleState());
try
{
// If HIWORD(lpcmi->lpVerb) then we have been called programmatically
// and lpVerb is a command that should be invoked. Otherwise, the
// shell has called us, and LOWORD(lpcmi->lpVerb) is the menu ID the
// user has selected. Actually, it's (menu ID - idCmdFirst) from
// QueryContextMenu().
if (!HIWORD(lpcmi->lpVerb))
{
CString command;
PGPBoolean isNonTargeted, sendRequest;
UINT idCmd = LOWORD(lpcmi->lpVerb);
hr = NOERROR;
isNonTargeted = FALSE;
sendRequest = TRUE;
switch (idCmd)
{
case 0:
if (mNumTotalPGPdisks > 1)
command = GetCommonString(kPGPdiskOpenCmdString);
else if (mNumMountedPGPdisks == 1)
command = GetCommonString(kPGPdiskUnmountCmdString);
else
command = GetCommonString(kPGPdiskMountCmdString);
break;
case 1:
command = GetCommonString(kPGPdiskAddPassCmdString);
break;
case 2:
command = GetCommonString(kPGPdiskChangePassCmdString);
break;
case 3:
if (mShiftKeyDown)
command = GetCommonString(kPGPdiskRemoveAltsCmdString);
else
command = GetCommonString(kPGPdiskRemovePassCmdString);
break;
case 4:
command = GetCommonString(kPGPdiskPubKeysCmdString);
break;
case 5:
command = GetCommonString(kPGPdiskHelpCmdString);
isNonTargeted = TRUE;
break;
default:
hr = E_INVALIDARG;
sendRequest = FALSE;
break;
}
if (sendRequest)
SendRequestToApp(command, isNonTargeted);
}
}
catch (CMemoryException *ex)
{
ex->Delete();
}
return hr;
}
// GetCommandString returns the help string associated with a command.
STDMETHODIMP
CShellExt::GetCommandString(
UINT idCmd,
UINT uFlags,
UINT FAR *reserved,
LPSTR pszName,
UINT cchMax)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
try
{
CString helpString;
switch (idCmd)
{
case 0:
if (mNumTotalPGPdisks > 1)
{
helpString =
GetCommonString(kPGPdiskShellExtDescribeOpenString);
}
else if (mNumMountedPGPdisks == 1)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -