簡體   English   中英

查找圖像類型(gif、bmp、jpg 等)的預覽處理程序 GUID

[英]Finding preview handler GUIDs for image types (gif, bmp, jpg, etc)

如果您使用 Windows 資源管理器並單擊 .docx 或 .jpg 文件之類的項目,您將獲得在資源管理器中單擊的項目的預覽,如下所示 我正在嘗試在我的 windows 窗體應用程序中復制它,它適用於 .docx 和 .xlsx 文件,但不適用於圖像文件類型。 據我了解,預覽處理程序在 filextension/ShellEx 中的 GUID {8895b1c6-b41f-4c1c-a562-0d564250836f} 下注冊。 使用 regedit 您可以看到 .docx 文件具有這些.docx previewhandler GUID ,但是當您查看 .jpg 之類的內容時,什么也找不到。 i.stack.imgur.com/40v6h.png )。 (我不允許發布超過 2 個鏈接)

根據這篇文章的第一個答案( stackoverflow.com/questions/39373357/how-to-get-the-icon-path-and-index-related-with-a-file-type )還有其他位置預覽處理程序可能存儲在 .jpg 中,但對我來說它們都顯示為空。

我的問題:如何獲取窗口可以找到但我不能找到的擴展類型的預覽處理程序。 我認為在某處存儲了預覽處理程序,但我不知道它們在哪里或如何到達它們。

這是我用來獲取文件 GUID 的代碼。 .docx 和 .xlsx 類型成功,但圖像類型不成功。 我經過了最后一個鏈接中提到的每個位置,但它們都變成了空值。

    private Guid GetPreviewHandlerGUID(string filename)
    {
        // open the registry key corresponding to the file extension
        string extention = Path.GetExtension(filename);
        RegistryKey ext = RegistryKey.OpenBaseKey(RegistryHive.ClassesRoot, RegistryView.Registry64);

        // open the key that indicates the GUID of the preview handler type
        string className = Convert.ToString(ext.GetValue(null));
        RegistryKey test = ext.OpenSubKey(className + "\\ShellEx\\{8895b1c6-b41f-4c1c-a562-0d564250836f}");
        if (test != null) return new Guid(Convert.ToString(test.GetValue(null)));
        // sometimes preview handlers are declared on key for the class
        if (className != null) {
                test = ext.OpenSubKey(extention + "\\ShellEx\\{8895b1c6-b41f-4c1c-a562-0d564250836f}");
            if (test == null)
                test = ext.OpenSubKey("SystemFileAssociations\\" + className + "\\ShellEx\\{8895b1c6-b41f-4c1c-a562-0d564250836f}");
            if (test == null)
                test = ext.OpenSubKey("SystemFileAssociations\\" + extention + "\\ShellEx\\{8895b1c6-b41f-4c1c-a562-0d564250836f}");
            if (test == null)
                test = ext.OpenSubKey("SystemFileAssociations\\image\\ShellEx\\{8895b1c6-b41f-4c1c-a562-0d564250836f}");
            if (test != null) return new Guid(Convert.ToString(test.GetValue(null)));
        }

        return Guid.Empty;
    }

這是我在這里的第一篇文章,所以我希望我能提供足夠的信息。 如果有遺漏的東西,我會在有機會時添加它們。 謝謝。

那是在本地機器下:

HKEY_LOCAL_MACHINE\\Software\\Classes\\giffile\\shellex{8895b1c6-b41f-4c1c-a562-0d564250836f}

我通過反編譯 PreviewConfig http://www.winhelponline.com/blog/previewconfig-tool-registers-file-types-for-the-preview-pane-in-windows-vista/得到了這個

您應該使用AssocQueryString函數,而不是自己爬取注冊表。

你告訴它.jpg ,以及你正在尋找的 shell 處理程序:

  • {BB2E617C-0920-11d1-9A0B-00C04FC2D6C1} :IExtractImage
  • {953BB1EE-93B4-11d1-98A3-00C04FB687DA} :IExtractImage2
  • {8895b1c6-b41f-4c1c-a562-0d564250836f} :IPreviewHandler
  • {e357fccd-a995-4576-b01f-234630154e96} :IThumbnailProvider

它將返回該處理程序的 clsid。

C#風格的偽代碼

private Guid GetShellObjectClsid(String filename, Guid desiredHandler)
{
    String ext = Path.GetExtension(filename);
    String sInterfaceID = desiredHandler.ToString("B"); // B ==> The COM format {xxxx}

    uint bufferLen = 100; //more than enough to hold a 38 character clsid
    StringBuilder buffer = new StringBuilder(bufferLen);

    HRESULT hr = AssocQueryString(ASSOCF_INIT_DEFAULTTOSTAR, ASSOCSTR_SHELLEXTENSION, 
          ext, buffer, ref bufferLen);
    if (hr != S_OK)
    {
       //Marhsal.ThrowExceptionForHR(hr);
       return null;
    }

    String s = sb.ToString();

    return new Guid(sb.ToString());   
}

所以現在如果你想要一個文件類型的IPreviewHandler

Guid previewHandlerClsid = GetShellObjectClsid("a.jpg", IID_IPreviewHandler);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM