Extract high resolution icon or thumbnail for file

前端 未结 2 1083
心在旅途
心在旅途 2020-12-15 11:00

I\'m trying to get a high resolution icon or thumbnail in Windows given a full path to that file. Doesn\'t need to be a thumbnail — a good looking Icon will be grea

相关标签:
2条回答
  • 2020-12-15 11:11

    Have you tried ExtractIconEx()?

    It has dedicated parameters to extract arrays of both small and large icons from executables, DLLs, or icon files. From there you can select the size best suited to your needs. The API call is available from Win2K onwards.

    0 讨论(0)
  • 2020-12-15 11:22

    If you are targeting Vista and higher, you can get a 256x256 icon from the jumbo image list. If you need to target XP, you can at least use the extra large image list, which is 48x48 (slightly better than 32x32 large).

    #include <commoncontrols.h>
    #include <shellapi.h>
    
    HICON GetHighResolutionIcon(LPTSTR pszPath)
    {
        // Get the image list index of the icon
        SHFILEINFO sfi;
        if (!SHGetFileInfo(pszPath, 0, &sfi, sizeof(sfi), SHGFI_SYSICONINDEX)) return NULL;
    
        // Get the jumbo image list
        IImageList *piml;
        if (FAILED(SHGetImageList(SHIL_JUMBO, IID_PPV_ARGS(&piml))) return NULL;
    
        // Extract an icon
        HICON hico;
        piml->GetIcon(sfi.iIcon, ILD_TRANSPARENT, &hico);
    
        // Clean up
        piml->Release();
    
        // Return the icon
        return hico;
    }
    
    0 讨论(0)
提交回复
热议问题