Help Center

AddIconToItemfunction

Adds a bitmap to the menu item.

Windowsfunctiondoc-orphan
No implementation located. This member is documented, but the source scan found no matching declaration. It is likely declared in a header this scan does not resolve, or provided by a macro.

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

NameDescription
hMenuHandle to the menu that contains the menu item.
uItemThe identifier or position of the menu item to get information about. The meaning of this parameter depends on the value of fByPosition.
fByPositionThe meaning of uItem. If this parameter is FALSE, uItem is a menu item identifier. Otherwise, it is a menu item position.
hIconHandle of the icon to add to the menu.
fAutoDestroyTRUE (the default) or FALSE. If TRUE, AddIconToItem destroys the icon before returning.
phbmpOut. 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