@@ -1427,6 +1427,49 @@ namespace Win32Utils
14271427 return hReturn;
14281428 }
14291429
1430+ HBITMAP LoadIconFromFileAsBitmap32Bpp (const char * filename, int index)
1431+ {
1432+ HBITMAP hBitmap = INVALID_BITMAP_HANDLE;
1433+ HICON hIconSmall = NULL ;
1434+
1435+ std::wstring icon_filename_wide = ra::unicode::Utf8ToUnicode (filename);
1436+
1437+ // check how many icons the file contains
1438+ UINT num_icon_in_file = ExtractIconExW (icon_filename_wide.c_str (), -1 , NULL , NULL , 1 );
1439+ if (num_icon_in_file == 0 )
1440+ {
1441+ // ERROR: "File '" << filename << "' does not contains an icon.";
1442+ }
1443+ else
1444+ {
1445+ // the file contains 1 or more icons, try to load a small one
1446+ UINT num_icon_loaded = 0 ;
1447+ if (num_icon_in_file >= 1 )
1448+ num_icon_loaded = ExtractIconExW (icon_filename_wide.c_str (), index, NULL , &hIconSmall, 1 );
1449+ if (num_icon_in_file >= 1 && num_icon_loaded == 0 )
1450+ {
1451+ // ERROR: "Failed to load icon index " << icon_index << " from file '" << icon_filename << "'.";
1452+ }
1453+ else
1454+ {
1455+ SIZE menu_icon_size = Win32Utils::GetIconSize (hIconSmall);
1456+ // ERROR: "Loaded icon " << icon_index << " from file '" << icon_filename << "' is " << menu_icon_size.cx << "x" << menu_icon_size.cy << ".";
1457+
1458+ // Convert the icon to a 32bpp bitmap with alpha channel (invisible background)
1459+ hBitmap = Win32Utils::CopyAsBitmap (hIconSmall);
1460+ if (hBitmap == INVALID_BITMAP_HANDLE)
1461+ {
1462+ // ERROR: "Icon " << icon_index << " from file '" << icon_filename << "' has failed to convert to bitmap.";
1463+ }
1464+
1465+ if (hIconSmall != NULL )
1466+ DestroyIcon (hIconSmall);
1467+ }
1468+ }
1469+
1470+ return hBitmap;
1471+ }
1472+
14301473 BOOL IsFullyTransparent (HBITMAP hBitmap)
14311474 {
14321475 SIZE bitmap_size = GetBitmapSize (hBitmap);
0 commit comments