You can use Windows shell to create context menus same as that of windows for folders and files.
Following code prepares context menu same as that of Windows created for My Documents folder.
Please call
CMyTestDlg::ShowContextMenu()
from your dialog class.
HRESULT GetSHContextMenu(LPSHELLFOLDER psfFolder, LPCITEMIDLIST localPidl,
void** ppCM, int* pcmType)
{
*ppCM = NULL;
LPCONTEXTMENU pICv1 = NULL;
HRESULT hr = psfFolder->GetUIObjectOf(NULL, 1, &localPidl,
IID_IContextMenu, NULL, (void**)&pICv1);
if(pICv1) {
hr = pICv1->QueryInterface(IID_IContextMenu3, ppCM);
if(NOERROR == hr) *pcmType = 3;
else {
hr = pICv1->QueryInterface(IID_IContextMenu2, ppCM);
if(NOERROR == hr) *pcmType = 2;
}
if(*ppCM) pICv1->Release();
else {
*pcmType = 1;
*ppCM = pICv1;
hr = NOERROR;
}
}
return hr;
}
void CMyTestDlg::ShowContextMenu()
{
#define MIN_SHELL_ID 1
#define MAX_SHELL_ID 30000
CMenu menu;
menu.CreatePopupMenu();
int cmType;
LPCONTEXTMENU pCM;
IShellFolder *psfParent = NULL;
LPITEMIDLIST pidlSystem = NULL;
LPCITEMIDLIST pidlRelative = NULL;
STRRET strDispName;
TCHAR szDisplayName[MAX_PATH];
HRESULT hr;
hr = SHGetFolderLocation(NULL, CSIDL_MYDOCUMENTS, NULL, NULL, &pidlSystem);
hr = SHBindToParent(pidlSystem, IID_IShellFolder, (void **) &psfParent, &pidlRelative);
HRESULT hr1 = GetSHContextMenu(psfParent, pidlRelative, (void**)&pCM, &cmType);
hr = pCM->QueryContextMenu(menu, 0, MIN_SHELL_ID, MAX_SHELL_ID, CMF_EXPLORE);
int cmdID = menu.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN, 0, 0, this);
}
Here is an example in MSDN, same as that of your application:
http://www.microsoft.com/msj/0497/wicked/wicked0497.aspx
MSDN link to get Information About the Contents of a Folder
http://msdn.microsoft.com/en-us/library/windows/desktop/bb776885(v=vs.85).aspx
Shell context menu support:
http://netez.com/2xExplorer/shellFAQ/bas_context.html#getmenu