如何使用 Windows API 获取文件缩略图? [英] How to get thumbnail of file using the Windows API?

查看:96
本文介绍了如何使用 Windows API 获取文件缩略图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 Windows API 中获取文件的缩略图.我确实找到了一种方法,但是代码示例至少需要 Windows 版本 8,我更喜欢一种至少可以在 7 或 Vista 中运行的方法,最好是在 XP 中.如果有一种独立于平台的获取缩略图的方式,我更愿意这样做,但我一直找不到.

I'm trying to get a thumbnail of a file in Windows API. I did find a way, but the code example requires Windows version 8 minimum, I would prefer a way that works in at least 7 or Vista, preferably in XP. If there is a platform independent way of obtaining the thumbnail I would prefer to do that, but I haven't been able to find one.

推荐答案

没有适用于所有 Windows 版本的单一 API,因为 Microsoft 不断将缩略图 API 从一个 Windows 版本更改为另一个.

There is no single API that works on all Windows versions, because Microsoft keeps changing the thumbnail APIs from one Windows version to another.

在 Win2K 及包括 Vista(不确定更高版本)上,您可以检索 IShellFolder 用于使用 SHGetDesktopFolder()IShellFolder::ParseDisplayName()(或SHParseDisplayName()(XP 及更高版本),然后使用 IShellFolder::GetUIObjectOf() 以检索所需的子文件的 IExtractImage 接口,然后调用其GetLocation() 方法来设置图像大小及其Extract() 检索实际图像的方法.

On Win2K up to and including Vista (not sure about later versions), you can retrieve an IShellFolder for the file's parent folder using SHGetDesktopFolder() and IShellFolder::ParseDisplayName() (or SHParseDisplayName() on XP and later), then use IShellFolder::GetUIObjectOf() to retrieve the desired child file's IExtractImage interface, and then call its GetLocation() method to set the image size and its Extract() method to retrieve the actual image.

在 Vista 及更高版本上,您可以:

On Vista and later, you can either:

1) 使用 IThumbnailProvider.查询其 IInitializeWith... 接口之一 (IInitializeWithStream, IInitializeWithItemIInitializeWithFile) 告诉它你对哪个文件感兴趣,然后调用它的 GetThumbnail() 获取实际图像的方法.或者,您可以获得 IShellItem 获取所需文件,然后调用其 BindToHandler 方法获取文件的IThumbnailProvider.

1) use IThumbnailProvider. Query it for one of its IInitializeWith... interfaces (IInitializeWithStream, IInitializeWithItem, or IInitializeWithFile) to tell it which file you are interested in, and then call its GetThumbnail() method to get the actual image. Alternatively, you can get an IShellItem for the desired file and then call its BindToHandler method to obtain the file's IThumbnailProvider.

2) 使用 IThumbnailCache.传递 IShellItem 表示所需文件到其 GetThumbnail() 获取图像的方法.

2) use IThumbnailCache. Pass an IShellItem representing the desired file to its GetThumbnail() method to get the image.

3) 使用 IShellItemImageFactory.使用 SHCreateItemFrom...() 函数之一 (SHCreateItemFromIDList(), SHCreateItemFromParsingName(), SHCreateItemFromRelativeName(), SHCreateItemInKnownFolder(), SHCreateItemWithParent()) 获取给定文件的此接口,然后调用其 GetImage() 方法.

3) use IShellItemImageFactory. Use one of the SHCreateItemFrom...() functions (SHCreateItemFromIDList(), SHCreateItemFromParsingName(), SHCreateItemFromRelativeName(), SHCreateItemInKnownFolder(), SHCreateItemWithParent()) to obtain this interface for a given file, then call its GetImage() method.

这篇关于如何使用 Windows API 获取文件缩略图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆