Windows 文件预览 - 类似于资源管理器中的预览窗格
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5188959/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Windows file preview - similar to preview pane in explorer
提问by Jason
In Windows 7 (and I think Vista) the Explorer has a preview pane that lets you see the contents for some file types (MS Office, images, etc). Is there any API available that allows you to access this functionality?
在 Windows 7(我认为是 Vista)中,资源管理器有一个预览窗格,可让您查看某些文件类型(MS Office、图像等)的内容。是否有任何可用的 API 允许您访问此功能?
I've been using the WindowsAPICodePackwhich has a ShellFile.Thumbnail, but this seems to only expose the thumbnail icon for file types that Explorer is able to view. For instance, for a Word file it only displays the MS Word icon, where Explorer can actually preview the contents of the file. It does work like I want for image types, but not for other types of files.
我一直在使用具有 ShellFile.Thumbnail的WindowsAPICodePack,但这似乎只公开资源管理器能够查看的文件类型的缩略图图标。例如,对于 Word 文件,它只显示 MS Word 图标,资源管理器实际上可以在其中预览文件的内容。它确实像我想要的图像类型一样工作,但不适用于其他类型的文件。
采纳答案by user541686
回答by John Arlen
Sample code (though hard to read... have to highlight the text) is here: Hosting vista/office 2007 previewers in winform application
示例代码(虽然难以阅读......必须突出显示文本)在这里: Hosting vista/office 2007 previewers in winform application
回答by Joachim Marder
回答by Thomas Weller
For simple text previews you can also add a Registry key
对于简单的文本预览,您还可以添加注册表项
[HKEY_CLASSES_ROOT\.ext]
"PerceivedType"="text"
For more complex stuff, Microsoft provides the Shell Interface IPreviewHandler [MSDN]that you can implement as a COM object to provide a custom preview. There is a C++ example [MSDN]available as well.
对于更复杂的内容,Microsoft 提供了 Shell Interface IPreviewHandler [MSDN],您可以将其实现为 COM 对象以提供自定义预览。还有一个C++ 示例 [MSDN]可用。
The object will be initialized via IInitializeWithFile [MSDN]or IInitializeWithStream [MSDN]
该对象将通过IInitializeWithFile [MSDN]或IInitializeWithStream [MSDN]初始化
Once you implemented it, you need to register it on your system [MSDN]for different file type like this:
一旦你实现了它,你需要在你的系统 [MSDN] 上为不同的文件类型注册它,如下所示:
HKEY_CLASSES_ROOT
xyzfile
shellex
{8895b1c6-b41f-4c1c-a562-0d564250836f}
(Default) = [REG_SZ] {<Class-ID-of-your-COM-object>}