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?
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).
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)