2014-02-18 35 views
0

目前,我正在寫一個外殼擴展。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; 
} 

可有人建議如何獲得準確的路徑,而不是目標?

+0

您是否已經看到:http://www.codeproject.com/Articles/445/The-Complete-Idiot-s-Guide-to-Writing-Shell-Extens –

+0

感謝您的鏈接,但是這並不解決我的問題。 – ST3

+0

您必須實現IShellLink接口。 – user2120666

回答

3

(我不知道,下面的解決方案是絕對正確的,也許在某些情況下將無法正常工作,但在標準的情況下,我已經測試過它工作正常)

你必須先註冊你在上下文菜單句柄*和lnkfile。這意味着當用戶右鍵單擊快捷鍵QueryContextMenu時會被調用兩次。第一次用於快捷文件目標,第二次用於快捷文件本身。但是有一點差異。對於快捷方式文件,目標shell總是通過CMF_VERBSONLY,並且此標誌對於快捷方式文件本身不存在。所以只需檢查這個標誌並且如果存在就不加任何東西

+0

你在說靜態動詞還是動態外殼擴展? – ST3

+0

@ ST3我講的動態 –

+0

偉大的答案,謝謝:)運行完美。 – ST3