Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create windows right click context menu for SPECIFIC folders

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.

like image 538
Prince Mishra Avatar asked May 21 '12 13:05

Prince Mishra


2 Answers

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

like image 70
tol Avatar answered Sep 30 '22 13:09

tol


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;

}
like image 22
Xearinox Avatar answered Sep 30 '22 11:09

Xearinox