Code: Select all
HICON hIcon = nullptr;
ICONINFO icon;
IImageListPtr spiml;
int iconSize = SHIL_EXTRALARGE;
if (IsWindowsVistaOrGreater())
{
iconSize = SHIL_JUMBO;
}
// Find the proper icon to use.
// I was dreading this part until I found out it's
// literally three functions.
SHGetFileInfo(path, 0, &info, sizeof(info), SHGFI_SYSICONINDEX);
SHGetImageList(iconSize, IID_PPV_ARGS(&spiml));
spiml->GetIcon(info.iIcon, ILD_TRANSPARENT, &hIcon);
// Load icon image data
GetIconInfo(hIcon, &icon);
// At this point `icon` contains hbmColor which *should* contain the color
// bitmap info, including an alpha channel if present. Bonus points: supports
// .exe & .ico, and offers a sane default for any file type GDI+ doesn't handle