目前,我正在寫一個外殼擴展。Windows外殼擴展沒有給出確切的文件路徑
如果我右鍵單擊快捷方式單一(* .lnk文件),我得到它的目標路徑,如果我選擇多個文件和快捷方式右擊我只得到一個文件 - 快捷方式的目標文件。
我的外殼擴展還沒有完成,但其中列舉了文件中的代碼部分是這樣的:
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;
}
可有人建議如何獲得準確的路徑,而不是目標?
您是否已經看到:http://www.codeproject.com/Articles/445/The-Complete-Idiot-s-Guide-to-Writing-Shell-Extens –
感謝您的鏈接,但是這並不解決我的問題。 – ST3
您必須實現IShellLink接口。 – user2120666