Read Explorer Thumbnail

I want to read the system / explorer thumbnail for a non specific file (Word, Excel, JPEG, PDF…) under Windows 7+. Under OS X I use a QuickLook function (MBS). I found this command Shellfile.Thumbnail.Largebitmap. But I think it’s C#. Is it possible to read the thumbnail via declares?

Any suggestions are welcome…

Greetings from germany


I didn’t find a Win32 equivalent. If someone knows one, I’d love to add to my plugins.

For the older Windows versions

This should work, pass the extension and the desired icon size:

Function DefaultIconForFileType(extension As String, size As Integer = 32) As Picture Declare Function SHGetFileInfoW Lib "Shell32" (FilePath As WString, Attribs As Integer, info As Ptr, infoSize As Integer, flags As Integer) As Boolean Declare Function DrawIconEx Lib "User32" (hDC As Integer, xLeft As Integer, yTop As Integer, hIcon As Integer, cxWidth As Integer, cyWidth As Integer, istepIfAniCur As Integer, hbrFlickerFreeDraw As Integer, diFlags As Integer) As Boolean Declare Function DestroyIcon Lib "User32" (hIcon As Integer) As Integer Const FILE_ATTRIBUTE_NORMAL = &h00000080 Const SHGFI_DISPLAYNAME = &h000000200 Const SHGFI_TYPENAME = &h000000400 Const SHGFI_USEFILEATTRIBUTES = &h000000010 Const SHGFI_ICON = &h000000100 Dim info As New MemoryBlock(352) If SHGetFileInfoW("foo." + extension, FILE_ATTRIBUTE_NORMAL, info, info.Size, SHGFI_DISPLAYNAME Or SHGFI_TYPENAME Or SHGFI_USEFILEATTRIBUTES Or SHGFI_ICON) Then Dim theIcon As Picture = New Picture(size, size, 32) theIcon.Transparent = 1 Call DrawIconEx(theIcon.Graphics.Handle(1), 0, 0, info.Int32Value(0), size, size, 0, 0, &h3) Call DestroyIcon(info.Int32Value(0)) Return theIcon Else Return Nil End If End Function

I think that returns a system icon, the original question asks for a thumbnail, which is a sort of quicklook icon for Windows (a thumbnail with the file contents).

I found this VB sample code which extracts thumbnails via the Windows Shell. Haven’t tried it yet, but maybe worth a look.

Sorry, I misunderstood the question. To access shell preview handlers objects I think you’ll need to use COM which I’m not very familiar with.

I think I got it working for next plugins.
Just needed half day on this :slight_smile:

The shell solution?

Plugin calls the shell icon factory and gets nice thumbnails.
And even flips images if they are upside down. Also provides masks, so we have good images.

if you want to try, I could email you a copy.
(email we if you want one)