AddIconToItemfunction
Adds a bitmap to the menu item.
Syntax
FUNCTION AddIconToItem (BYVAL hMenu AS HMENU, BYVAL uItem AS DWORD, BYVAL fByPosition AS BOOLEAN, BYVAL hIcon AS HICON, BYVAL fAutoDestroy AS BOOLEAN = TRUE, BYVAL phbmp AS HBITMAP PTR = NULL) AS BOOLEAN
Parameters
| Name | Description | |
|---|---|---|
hMenu | Handle to the menu that contains the menu item. | |
uItem | The identifier or position of the menu item to get information about. The meaning of this parameter depends on the value of fByPosition. | |
fByPosition | The meaning of uItem. If this parameter is FALSE, uItem is a menu item identifier. Otherwise, it is a menu item position. | |
hIcon | Handle of the icon to add to the menu. | |
fAutoDestroy | TRUE (the default) or FALSE. If TRUE, AddIconToItem destroys the icon before returning. | |
phbmp | Out. Location where the bitmap representation of the icon is stored. Can be NULL. |
Return value
TRUE or FALSE.
Description
Converts an icon handle to a bitmap and adds it to the specified hbmpItem field of HMENU item.
Remarks
The caller is responsible for destroying the bitmap generated. The icon will be destroyed if fAutoDestroy is set to true. The hbmpItem field of the menu item can be used to keep track of the bitmap by passing NULL to phbmp.
Using AfxGdipAddIconFromFile or AfxGdipIconFromRes to load the image from a file or resource and convert it to a icon you can use alphablended .png icons.
Examples
DIM hSubMenu AS HMENU = CMenu.GetSubMenu(hMenu, 1) DIM hIcon AS HICON = LoadImageW(NULL, ExePath & "\undo_32.ico", IMAGE_ICON, 32, 32, LR_LOADFROMFILE) IF hIcon THEN CMenu.AddIconToItem(hSubMenu, 0, TRUE, hIcon)
DIM hSubMenu AS HMENU = CMenu.GetSubMenu(hMenu, 1) CMenu.AddIconToItem(hSubMenu, 0, TRUE, AfxGdipIconFromRes(hInstance, "IDI_UNDO_32"))
Loading the icon from disk:
Loading the icon from a resource file:
Reference
- Documented in Windows/WIndows Controls/CMenu Class.md
- Topic: About Menus