Skip to content

Commit 728f982

Browse files
committed
Modernize CItemManager::LoadCustomIcon
1 parent 2ca236c commit 728f982

File tree

1 file changed

+25
-33
lines changed

1 file changed

+25
-33
lines changed

Src/StartMenu/StartMenuDLL/ItemManager.cpp

Lines changed: 25 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2595,49 +2595,41 @@ void CItemManager::IconInfo::SetPath( const wchar_t *path )
25952595
timestamp.dwHighDateTime=timestamp.dwLowDateTime=0;
25962596
}
25972597

2598-
void CItemManager::LoadCustomIcon( const wchar_t *iconPath, int iconIndex, int refreshFlags, const IconInfo *&smallIcon, const IconInfo *&largeIcon, const IconInfo *&extraLargeIcon, bool bTemp )
2598+
void CItemManager::LoadCustomIcon(const wchar_t *iconPath, int iconIndex, int refreshFlags, const IconInfo *&smallIcon, const IconInfo *&largeIcon, const IconInfo *&extraLargeIcon, bool bTemp)
25992599
{
2600-
unsigned int hash=CalcFNVHash(iconPath,CalcFNVHash(&iconIndex,4));
2600+
unsigned int hash = CalcFNVHash(iconPath, CalcFNVHash(&iconIndex, 4));
26012601

2602-
FindInCache(hash,refreshFlags,smallIcon,largeIcon,extraLargeIcon);
2603-
if (!refreshFlags) return;
2602+
FindInCache(hash, refreshFlags, smallIcon, largeIcon, extraLargeIcon);
2603+
if (!refreshFlags)
2604+
return;
26042605

2605-
// extract icon
2606-
HBITMAP hSmallBitmap=NULL, hLargeBitmap=NULL, hExtraLargeBitmap=NULL;
2607-
if (refreshFlags&INFO_SMALL_ICON)
2608-
{
2606+
auto ExtractIconAsBitmap = [&](int iconSize) -> HBITMAP {
26092607
HICON hIcon;
2610-
if (!*iconPath)
2611-
hIcon=(HICON)LoadImage(g_Instance,MAKEINTRESOURCE(-iconIndex),IMAGE_ICON,SMALL_ICON_SIZE,SMALL_ICON_SIZE,LR_DEFAULTCOLOR);
2612-
else
2613-
hIcon=ShExtractIcon(iconPath,iconIndex==-1?0:iconIndex,SMALL_ICON_SIZE);
2614-
if (hIcon)
2615-
hSmallBitmap=BitmapFromIcon(hIcon,SMALL_ICON_SIZE);
2616-
}
26172608

2618-
if (refreshFlags&INFO_LARGE_ICON)
2619-
{
2620-
HICON hIcon;
26212609
if (!*iconPath)
2622-
hIcon=(HICON)LoadImage(g_Instance,MAKEINTRESOURCE(-iconIndex),IMAGE_ICON,LARGE_ICON_SIZE,LARGE_ICON_SIZE,LR_DEFAULTCOLOR);
2610+
hIcon = (HICON)LoadImage(g_Instance, MAKEINTRESOURCE(-iconIndex), IMAGE_ICON, iconSize, iconSize, LR_DEFAULTCOLOR);
26232611
else
2624-
hIcon=ShExtractIcon(iconPath,iconIndex==-1?0:iconIndex,LARGE_ICON_SIZE);
2625-
if (hIcon)
2626-
hLargeBitmap=BitmapFromIcon(hIcon,LARGE_ICON_SIZE);
2627-
}
2612+
hIcon = ShExtractIcon(iconPath, iconIndex == -1 ? 0 : iconIndex, iconSize);
26282613

2629-
if (refreshFlags&INFO_EXTRA_LARGE_ICON)
2630-
{
2631-
HICON hIcon;
2632-
if (!*iconPath)
2633-
hIcon=(HICON)LoadImage(g_Instance,MAKEINTRESOURCE(-iconIndex),IMAGE_ICON,EXTRA_LARGE_ICON_SIZE,EXTRA_LARGE_ICON_SIZE,LR_DEFAULTCOLOR);
2634-
else
2635-
hIcon=ShExtractIcon(iconPath,iconIndex==-1?0:iconIndex,EXTRA_LARGE_ICON_SIZE);
26362614
if (hIcon)
2637-
hExtraLargeBitmap=BitmapFromIcon(hIcon,EXTRA_LARGE_ICON_SIZE);
2638-
}
2615+
return BitmapFromIcon(hIcon, iconSize);
2616+
2617+
return nullptr;
2618+
};
2619+
2620+
// extract icon
2621+
HBITMAP hSmallBitmap = nullptr, hLargeBitmap = nullptr, hExtraLargeBitmap = nullptr;
2622+
2623+
if (refreshFlags & INFO_SMALL_ICON)
2624+
hSmallBitmap = ExtractIconAsBitmap(SMALL_ICON_SIZE);
2625+
2626+
if (refreshFlags & INFO_LARGE_ICON)
2627+
hLargeBitmap = ExtractIconAsBitmap(LARGE_ICON_SIZE);
2628+
2629+
if (refreshFlags & INFO_EXTRA_LARGE_ICON)
2630+
hExtraLargeBitmap = ExtractIconAsBitmap(EXTRA_LARGE_ICON_SIZE);
26392631

2640-
StoreInCache(hash,bTemp?NULL:iconPath,hSmallBitmap,hLargeBitmap,hExtraLargeBitmap,refreshFlags,smallIcon,largeIcon,extraLargeIcon,bTemp,false);
2632+
StoreInCache(hash, bTemp ? nullptr : iconPath, hSmallBitmap, hLargeBitmap, hExtraLargeBitmap, refreshFlags, smallIcon, largeIcon, extraLargeIcon, bTemp, false);
26412633
}
26422634

26432635
// Recursive function to preload the items for a folder

0 commit comments

Comments
 (0)