[英]How can i get shortcut display name when mouse right-click in (c++/c#)
i'm buliding a dll about filecontextmenu , i need to get the execution path and shortcut displaynem when mouse right-click . 我正在建立一个关于filecontextmenu的dll,我需要在鼠标右键单击时获取执行路径和快捷方式displaynem。 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". EX:桌面上的IE快捷方式,我需要名称“IE”,可以由用户编辑,而不是“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;
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." 正如MSDN中所提到的,“建议处理程序使用Shell项目数组而不是剪贴板格式,如CF_HDROP和CFSTR_SHELLIDLIST(也称为HIDA),因为它会导致更简单的代码并允许一些性能改进。”
So, firstly call SHCreateShellItemArrayFromDataObject() on pDataObj and retrieve IShellItemArray interface. 因此,首先在pDataObj上调用SHCreateShellItemArrayFromDataObject()并检索IShellItemArray接口。 Enumerate it with IShellItemArray::Count() and IShellItemArray::GetItemAt(). 使用IShellItemArray :: Count()和IShellItemArray :: GetItemAt()枚举它。
Each IShellItem object has an excellent GetDisplayName() method! 每个IShellItem对象都有一个出色的GetDisplayName()方法! 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 :-) 你有SIGDN_FILESYSPATH和SIGDN_NORMALDISPLAY ids的地方:-)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.