查找图像类型(gif, bmp, jpg等)的预览处理程序guid



如果你使用windows资源管理器并点击一个项目,比如。docx或。jpg文件,你会在资源管理器中得到你点击的项目的预览,就像这样。我试图在我的windows窗体应用程序中复制这一点,它适用于。docx和。xlsx文件,但它不适用图像文件类型。据我所知,预览处理程序在filextension/ShellEx中的GUID {8895b1c6-b41f-4c1c-a562-0d564250836f}下注册。使用regedit可以看到。docx文件有这些。docx预览处理程序GUID,但是当您查看。jpg之类的文件时,什么也找不到。( i.stack.imgur.com/40v6h.png )。(我不允许发布超过2个链接)

根据这篇文章的第一个答案(stackoverflow.com/questions/39373357/how-to-get-the-icon-path-and-index-associated-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 giffile 软件类shellex b1c6-b41f-4c1c-a562-0d564250836f {8895}

我得到这个通过反编译PreviewConfighttp://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

,它将返回该处理程序的类。

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);

最新更新