MCPcopy Create free account
hub / github.com/AutoHotkey/AutoHotkey / SetItemIcon

Method SetItemIcon

source/script_menu.cpp:1334–1364  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1332
1333
1334ResultType UserMenu::SetItemIcon(UserMenuItem *aMenuItem, LPTSTR aFilename, int aIconNumber, int aWidth)
1335{
1336 if (!*aFilename || (*aFilename == '*' && !aFilename[1]))
1337 return RemoveItemIcon(aMenuItem);
1338
1339 int image_type;
1340 HBITMAP new_icon, new_copy;
1341 // Currently height is always -1 and cannot be overridden. -1 means maintain aspect ratio, usually 1:1 for icons.
1342 if ( !(new_icon = LoadPicture(aFilename, aWidth, -1, image_type, aIconNumber, false)) )
1343 return FAIL;
1344
1345 if (image_type != IMAGE_BITMAP) // Convert to 32-bit bitmap:
1346 {
1347 new_copy = IconToBitmap32((HICON)new_icon, true);
1348 // Even if conversion failed, we have no further use for the icon:
1349 DestroyIcon((HICON)new_icon);
1350 if (!new_copy)
1351 return FAIL;
1352 new_icon = new_copy;
1353 }
1354
1355 if (aMenuItem->mBitmap) // Delete previous bitmap.
1356 DeleteObject(aMenuItem->mBitmap);
1357
1358 aMenuItem->mBitmap = new_icon;
1359
1360 if (mMenu)
1361 ApplyItemIcon(aMenuItem);
1362
1363 return aMenuItem->mBitmap ? OK : FAIL;
1364}
1365
1366
1367// Caller has ensured mMenu is non-NULL.

Callers

nothing calls this directly

Calls 2

LoadPictureFunction · 0.85
IconToBitmap32Function · 0.85

Tested by

no test coverage detected