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.
Method 1: Change File Explorer settings In the search box, type File Explorer Options. Select File Explorer Options from the menu. In the File Explorer Options window, click on the View tab. Uncheck Always show icons, never thumbnails option.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With