Results 1 to 4 of 4

Thread: [RESOLVED] How to get the image shown by Explorer when viewing by Medium/Large/Extra Large Icons

Threaded View

  1. #2
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    7,653

    Re: How to get the image shown by Explorer when viewing by Medium/Large/Extra Large I

    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:

    Code:
    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
    which is called like
    Code:
        pidl = ILCreateFromPathW(StrPtr(App.Path & "\Images\32.png"))
        hr = FileToHIML(himl, pidl, cxThumb, cyThumb, SIIGBF_THUMBNAILONLY)
        Call CoTaskMemFree(pidl)
    where himl is the handle to your imagelist (API imagelist; if you're not using that I can provide more details),

    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
    Last edited by fafalone; Aug 19th, 2017 at 07:52 PM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width