SECIContextMenuImpl Class

template <class T, class TPidlMgr>
class SECIContextMenuImpl: public IContextMenu

This class is a thin wrapper class of IContextMenu interface. It only implemented the methods in the IUnknown interface and the reference counting logic. It can only be used in an ATL base project. Since its reference counting makes use of the lock count in CComModule class of ATL, i.e. a global CComModule instanace _Module. This class must be derived before it can be used. The derived class should contain command map no matter there is any command inside or not as shown in Example One. To use this class, you just add the proper menu item into the command map in your derived class using the provided marcos. You then override the CommandHandler virtual function is your derived class as shown in the Example Two. This template class requires two template arguments. The first one is your derived class and the second one is an PIDL management class derived from SECPidlMgr template class. This implementation is majorly targeted for namespace or shell extension. The constructor need two arguments, a window handle and a PIDL. The window handle is usually the owner window of this interface. The constructor will save the window handle and make a copy of the PIDL. For a complete documentation of IContextMenu interface, please refer to windows SDK or MSDN from Microsoft.

Defined in: SECIContextMenuImpl.h

Example

One:
 class CMyContextMenu : public SECIContextMenuImpl<CMyContextMenu, SECPidlManager>
 {
 CMyContextMenu(HWND hwndOwner, LPCITEMIDLIST pidl)
 : SECIContextMenuImpl<CMyContextMenu, SECPidlManager>(hwndOwner, pidl)
 {}
 SEC_BEGIN_COMMAND_MAP()
 SEC_END_COMMAND_MAP()
 };
Two:
 class CMyContextMenu : public SECIContextMenuImpl<CMyContextMenu, SECPidlManager>
 {
public:
 CMyContextMenu(HWND hwndOwner, LPCITEMIDLIST pidl)
 : SECIContextMenuImpl<CMyContextMenu, SECPidlManager>(hwndOwner, pidl)
 {}
 #define ID_MYMENUITEM 101
 SEC_BEGIN_COMMAND_MAP()
 SEC_COMMAND(_T("Menu Text"), _T("Help string"), ID_MYMENUITEM)
 SEC_END_COMMAND_MAP()
 virtual void CommandHandler(HWND hwndOwner, UINT nID)
 {
 if( nID == ID_MYMENUITEM)
 ::MessageBox(hwndOwner, _T("Message"), _T("Title"), MB_OK);
 }
 };

Class Template Arguments

T

The derived class

TPidlMgr

SECPidlMgr derived class

Class Members

HWND  m_hwndOwner

The window handle of the owener of this interface

LPITEMIDLIST  m_pPidl

PIDL of the current item

TPidlMgr*  m_pPidlMgr

A pointer to PIDL mananger

vector<SECContextMenuItem*>  m_commands

A vector to store the context menu items

SECIContextMenuImpl(HWND hwndOwner, LPCITEMIDLIST pidl)

Constructor

virtual HRESULT  AddCommand(UINT nIDName, UINT nIDHelpString)

Add one menu item

virtual HRESULT  AddCommand(LPCTSTR strName, LPCTSTR strHelp, UINT nCommandID)

Add one menu item

virtual void  RemoveAllCommands()

Remove all the menu items

virtual void  CommandHandler(HWND hwndOwner, UINT nID)

A menu command handler