【发布时间】:2017-03-15 19:22:18
【问题描述】:
如果您使用 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,但它们对我来说都是空的。
我的问题:如何获取窗口可以找到但我找不到的扩展类型的预览处理程序。我认为在某处存储了预览处理程序,但我不知道它们在哪里或如何访问它们。
这是我用来获取文件 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;
}
这是我在这里的第一篇文章,所以我希望我能提供足够的信息。如果有遗漏的东西,我会在有机会时添加它们。谢谢。
【问题讨论】:
标签: c# image guid file-extension preview-handler