c# - 查找图像类型(gif、bmp、jpg 等)的预览处理程序 GUID

标签 c# image guid file-extension preview-handler

如果您使用 Windows 资源管理器并单击诸如 .docx 或 .jpg 文件之类的项目,您可以预览在资源管理器中单击的项目 like this .我试图在我的 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-associated-with-a-file-type) 对于 .jpg,预览处理程序可能存储在其他位置,但它们对我来说都是空的。

我的问题:如何获取 Windows 可以找到但我找不到的扩展类型的预览处理程序。我认为有些地方存储了预览处理程序,但我不知道它们在哪里或如何访问它们。

这是我用来获取文件 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/

关于c# - 查找图像类型(gif、bmp、jpg 等)的预览处理程序 GUID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40380653/

相关文章:

c# - 如何从配置文件重构高度重复的阅读部分

image - Grails图片网址已加载,但图片未加载?

php - Laravel 图片库逻辑

c# - Swashbuckle Swagger 生成一个实际的 guid

mysql - 在连接的 SQL 查询中编辑列

c# - 无法连接到任何指定的 mysql 主机。 C#

c# - 获取listview的item双击事件

html - 在以 HTML 加载图像之前获取图像高度

visual-studio - 重新创建 COM DLL,我需要担心 GUID 吗?

c# - 当查询字符串太复杂时,我们可以使用 HttpPost 代替 HttpGet 吗?