How can I get the display name of the shortcut when the mouse is right clicked (C ++ / C #)

I lock the dll on filecontextmenu, I need to get the execution path and displaynem shortcut when right click. Now I can get the path, but I don’t know how to get the display name. EX: IE Shortcut on the desktop, I need the name "IE", which the user can edit, not "iexplore.exe".

here the link is very similar, but I can’t find out what to do when the desktop shortcut

If there is any suggestion that I really 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; 
+4
source share
1 answer

As mentioned in MSDN: "It is recommended that handlers use an array of Shell elements rather than clipboard formats such as CF_HDROP and CFSTR_SHELLIDLIST (also known as HIDA), as it leads to simpler code and allows some performance improvements."

So first call SHCreateShellItemArrayFromDataObject () on pDataObj and get the IShellItemArray interface. List it using IShellItemArray :: Count () and IShellItemArray :: GetItemAt ().

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

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

If you have the identifiers SIGDN_FILESYSPATH and SIGDN_NORMALDISPLAY :-)

0
source

Source: https://habr.com/ru/post/1443560/


All Articles