【发布时间】:2014-02-18 09:03:37
【问题描述】:
目前我正在编写一个 Shell 扩展,因为扩展文件上下文菜单的常规方式不适合我的需要,但是我在这里遇到了同样的问题。
如果我右键单击单个快捷方式(*.lnk 文件),我会得到它的目标路径,如果我选择许多文件并右键单击快捷方式,我只会得到一个文件 - 快捷方式目标文件。
我的shell扩展还没有完成,但枚举文件的部分代码是这样的:
HRESULT CFileContextMenuExt::Initialize(PCIDLIST_ABSOLUTE pidlFolder, IDataObject *pdtobj, HKEY hkeyProgID)
{
HRESULT hr = E_INVALIDARG;
if (NULL == pdtobj)
{
return hr;
}
FORMATETC fe = { CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
STGMEDIUM stm = {};
// pDataObj contains the objects being acted upon. In this example,
// we get an HDROP handle for enumerating the selected files.
if (SUCCEEDED(pdtobj->GetData(&fe, &stm)))
{
// Get an HDROP handle.
HDROP hDrop = static_cast<HDROP>(GlobalLock(stm.hGlobal));
if (hDrop != NULL)
{
// Determine how many files are involved in this operation.
UINT nFiles = DragQueryFile(hDrop, 0xFFFFFFFF, NULL, 0);
if (nFiles != 0)
{
m_selectedFiles.clear();
//Enumerates the selected files and directories.
for (UINT i = 0; i < nFiles; i++)
{
// Get the next filename.
int size = DragQueryFile(hDrop, i, NULL, 0) + 1;
string_t str;
str.resize(size);
if (DragQueryFile(hDrop, i, &str[0], size) == 0)
continue;
m_selectedFiles.push_back(str);
}
hr = S_OK;
}
GlobalUnlock(stm.hGlobal);
}
ReleaseStgMedium(&stm);
}
// If any value other than S_OK is returned from the method, the context
// menu is not displayed.
return hr;
}
有人可以建议如何获得确切的路径而不是目标吗?
【问题讨论】:
-
你已经看过了吗:codeproject.com/Articles/445/…
-
感谢您的链接,但这并不能解决我的问题。
-
必须实现IShellLink接口。
标签: c++ windows shell shell-extensions