How can I create a context menu that appears for files/folders inside a particular folder.
Say there is a directory "D:\RandomCodes"
How do I create a custom context menu item "Open in MyApp" for any file/folder inside this? This menu item should not appear for any other directory. I know if I add the entry in HKCR/Directory/Shell, it'll work, but then it'll appear for all files and folders everywhere. Please guide me through this.
example:
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Folder\shell\NetBeans]
"AppliesTo"="System.ItemPathDisplay:\"NetBeansProjects\""
@="Open with NetBeans"
[HKEY_CLASSES_ROOT\Folder\shell\NetBeans\command]
@="\"C:\\Program Files\\NetBeans 7.2.1\\bin\\netbeans64.exe\" --open \"%1\""
more info here:
http://msdn.microsoft.com/en-us/library/cc144171%28VS.85%29.aspx
Is possible modifing your code for IShellExtInit:
STDMETHODIMP CShellExt::Initialize(LPCITEMIDLIST pidl,LPDATAOBJECT pDataObj,HKEY hk)
{
// Initialize can be called more than once
// If Initialize has already been called, release the old
// IDataObject pointer.
if (m_pDataObj)
{
m_pDataObj->Release();
}
// If a data object pointer was passed in, save it and
// extract the file name.
if (pDataObj == NULL)
return E_INVALIDARG;
m_pDataObj = pDataObj;
pDataObj->AddRef();
STGMEDIUM medium;
FORMATETC fe = {CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL};
UINT uCount;
HRESULT hr = pDataObj->GetData(&fe, &medium);
if (FAILED(hr))
return E_INVALIDARG;
// save the file name
if (DragQueryFile((HDROP) medium.hGlobal, 0xFFFFFFFF, NULL, 0)==1)
{
DragQueryFile((HDROP) medium.hGlobal, 0, m_szFile,
sizeof(m_szFile));
if (lstrcmpi(m_szFile, "D:\\RandomCodes") == 0)
{
hr = NOERROR;
}
else
hr = E_INVALIDARG;
}
else
hr = E_INVALIDARG;
ReleaseStgMedium(&medium);
return hr;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With