Thumbnail Extraction Using the Shell

Extract thumbnails from any file type which has a Shell thumbnail handler: folders, web pages, images and more!

Thumbnail Extraction Demonstration Project

Since Windows Me/2000, the Windows Shell has included a mechanism for extracting a small thumbnail image for any item in the namespace. This sample demonstrates how to use this function to get thumbnail images for web pages, images, Office documents - in fact anything that supports thumbnailing in Explorer.

About the Sample

The sample provides a VB class cThumbnailGenerator which provides simple access to thumbnail generation. The methods and properties of the class are:

  • DesiredWidth
    Gets/sets the width in pixels you'd like the thumbnail to be. Note that in Windows the default thumbnail size is 96 x 96 pixels.
  • DesiredHeight
    As DesiredWidth
  • FileName
    Gets/sets the filename of the object you want a thumbnail for.
  • Options>
    Gets/sets options used to control the thumbnail extraction. The main options are:
    • IEIFLAG_ASPECT - Requests that the extractor tries to draw using the aspect ratio specified by DesiredWidth/DesiredWidth, regardless of the actual dimensions of the object.
    • IEIFLAG_OFFLINE - Tells the extractor not to connect to the Internet for any content which isn't available offline.
    • IEIFLAG_SCREEN - Render the item as if for the screen (exclusive with IEIFLAG_ASPECT.
    • IEIFLAG_QUALITY - Request a higher quality image. This may be slower.
    Note that the IEIFLAG_ASYNC option is not supported: whilst some thumbnail generators support asynchronous generation, the host needs to create a background thread to generate the thumbnail, and this is difficult in VB. A simple alternative would be to package the cThumbnailGenerator into an out-of-process ActiveX Exe and run that in a new thread instead.
  • GetThumbnail
    Actually gets the thumbnail, if possible. If there is no thumbnail support for the selected object an error will be raised. Otherwise, a pcMemDc object containing the thumbnail is returned. This can be used to draw the thumbnail or convert it into a VB StdPicture object.
  • .

The sample code demonstrates using the class to extract thumbnails for any file you choose (assuming there is support for thumbnail generation). It includes most of the code for the vbAccelerator Folder Browser which is used to allow you to pick folders or files.

Which Thumbnails Can You Get?

In Windows 2000 and above, the system by default will provide thumbnail viewers for pictures (BMP, GIF, JPEG, PNG), video files (AVI, MPG etc), Office documents (DOC, PPT, XLS, WMF), Web pages (HTML, MHT) and e-mail messages (EML). Note that Office documents can be previewed only if they've been saved with an embedded preview picture - you need to check the box in the Properties dialog to enable this.

However, other thumbnail extractors can be freely added to the system (sample coming soon) so you might have the ability to preview other files. Whilst its probably possible to check whether there is a extractor for a particular file type by looking in the registry, its easier just to try and create a thumbnail for the file - you'll get an error if its not possible.