Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
914 views
in Technique[技术] by (71.8m points)

winapi - How to get thumbnail of file using the Windows API?

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

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.

On Vista and later, you can either:

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) use IThumbnailCache. Pass an IShellItem representing the desired file to its GetThumbnail() method to get the image.

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...