To get the best results like you see in Explorer, you need to use a combination of methods to handle every scenario: [VB6, Vista+] Advanced Thumbnail ListView: Icons, images, videos, framed small images
The main function of interest though, if you just want limited support, is the IShellItemImageFactory class:
which is called likeCode:Public Declare Function SHCreateItemFromIDList Lib "shell32" (ByVal pidl As Long, riid As UUID, ppv As Any) As Long Public Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long Public Declare Function ILCreateFromPathW Lib "shell32" (ByVal pwszPath As Long) As Long Public Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal PV As Long) ' Frees memory allocated by the shell Public Function FileToHIML(himl As Long, pidlFQ As Long, CX As Long, CY As Long, lFlags As SIIGBF) As Long Dim isiif As IShellItemImageFactory Dim hr As Long Dim hBmp As Long On Error GoTo e0 hr = SHCreateItemFromIDList(pidlFQ, IID_IShellItemImageFactory, isiif) hr = isiif.GetImage(CX, CY, lFlags, hBmp) If hr = S_OK Then FileToHIML = ImageList_Add(himl, hBmp, 0) DeleteObject hBmp Else FileToHIML = -1 End If Set isiif = Nothing Exit Function e0: Debug.Print "FileToHIML Error: " & Err.Description & ", hr=0x" & Hex$(hr) FileToHIML = -1 End Function
where himl is the handle to your imagelist (API imagelist; if you're not using that I can provide more details),Code:pidl = ILCreateFromPathW(StrPtr(App.Path & "\Images\32.png")) hr = FileToHIML(himl, pidl, cxThumb, cyThumb, SIIGBF_THUMBNAILONLY) Call CoTaskMemFree(pidl)
That will get a thumbnail if it has one (and the image file isn't smaller than the requested size; that's one of the exceptions the advanced thumbview handles).
If that fails (hr=-1), re-request it with SIIGBF_ICONONLY.
That covers all files; you still get the default icon for tiny images and any non-image file (the full size icon too; it will load 256x256 icons if requested).
You might also want to look at my new project, [VB6] Dynamic Resize: Use a slider to change ListView icon/thumbnail size on the fly





Reply With Quote
