Question

i'm buliding a dll about filecontextmenu , i need to get the execution path and shortcut displaynem when mouse right-click . now i can get the path ,but no idea how to get the displayname. EX: IE Shortcut in desktop, i need the name "IE" which can edit by user , not "iexplore.exe".

here is a reference very similar , but i can't find out i should to do , when the shortcut in the desktop

if there any suggestion i will very appreciate , here is my code and thanks.

IFACEMETHODIMP FileContextMenuExt::Initialize(
LPCITEMIDLIST pidlFolder, LPDATAOBJECT pDataObj, HKEY hKeyProgID)

if (NULL == pDataObj)
    return E_INVALIDARG;

HRESULT hr = E_FAIL;

FORMATETC fe = { CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
STGMEDIUM stm;

// The pDataObj pointer contains the objects being acted upon. In this 
// example, we get an HDROP handle for enumerating the selected files and 
// folders.
if (SUCCEEDED(pDataObj->GetData(&fe, &stm)))
{
    // Get an HDROP handle.
    HDROP hDrop = static_cast<HDROP>(GlobalLock(stm.hGlobal));

    if (hDrop != NULL)
    {
        UINT nFiles = DragQueryFileW(hDrop, 0xFFFFFFFF, NULL, 0);
        if (nFiles > 0)
        {
            vecSelectFiles.clear();
            std::vector<std::wstring> vecTotalFiles;
            vecTotalFiles.clear();
            for(int i=0; i<(int)nFiles; ++i)
            {
                wchar_t wszThisFile[MAX_PATH];
                memset(wszThisFile, 0, MAX_PATH*2);
                // Here get excution path
                if(DragQueryFileW(hDrop, i, wszThisFile, MAX_PATH) != 0)
                {
                    vecTotalFiles.push_back(wszThisFile);
                    hr = S_OK;
                }
            }
        }
        GlobalUnlock(stm.hGlobal);
    }
    ReleaseStgMedium(&stm);
}

// If any value other than S_OK is returned from the method, the context 
// menu item is not displayed.
return hr;
Was it helpful?

Solution

As mentioned in MSDN, "It is recommend that handlers use a Shell item array rather than clipboard formats like CF_HDROP and CFSTR_SHELLIDLIST (also known as HIDA) as it leads to simpler code and allows some performance improvements."

So, firstly call SHCreateShellItemArrayFromDataObject() on pDataObj and retrieve IShellItemArray interface. Enumerate it with IShellItemArray::Count() and IShellItemArray::GetItemAt().

Each IShellItem object has an excellent GetDisplayName() method! You ever can specify display type:

SIGDN_NORMALDISPLAY = 0x00000000,
SIGDN_PARENTRELATIVEPARSING = 0x80018001,
SIGDN_PARENTRELATIVEFORADDRESSBAR = 0x8001c001,
SIGDN_DESKTOPABSOLUTEPARSING = 0x80028000,
SIGDN_PARENTRELATIVEEDITING = 0x80031001,
SIGDN_DESKTOPABSOLUTEEDITING = 0x8004c000,
SIGDN_FILESYSPATH = 0x80058000,
SIGDN_URL = 0x80068000,

Where you have SIGDN_FILESYSPATH and SIGDN_NORMALDISPLAY ids :-)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top