CMenu::SetMenuItemBitmaps

 

Associates the specified bitmaps with a menu item.

Syntax

      BOOL SetMenuItemBitmaps(
   UINT nPosition,
   UINT nFlags,
   const CBitmap* pBmpUnchecked,
   const CBitmap* pBmpChecked 
);

Parameters

  • nPosition
    Specifies the menu item to be changed. The nFlags parameter can be used to interpret nPosition in the following ways:

    nFlags

    Interpretation of nPosition

    MF_BYCOMMAND

    Specifies that the parameter gives the command ID of the existing menu item. This is the default if neither MF_BYCOMMAND nor MF_BYPOSITION is set.

    MF_BYPOSITION

    Specifies that the parameter gives the position of the existing menu item. The first item is at position 0.

  • nFlags
    Specifies how nPosition is interpreted.

  • pBmpUnchecked
    Specifies the bitmap to use for menu items that are not checked.

  • pBmpChecked
    Specifies the bitmap to use for menu items that are checked.

Return Value

Nonzero if the function is successful; otherwise 0.

Remarks

Whether the menu item is checked or unchecked, Windows displays the appropriate bitmap next to the menu item.

If either pBmpUnchecked or pBmpChecked is NULL, then Windows displays nothing next to the menu item for the corresponding attribute. If both parameters are NULL, Windows uses the default check mark when the item is checked and removes the check mark when the item is unchecked.

When the menu is destroyed, these bitmaps are not destroyed; the application must destroy them.

The Windows GetMenuCheckMarkDimensions function retrieves the dimensions of the default check mark used for menu items. The application uses these values to determine the appropriate size for the bitmaps supplied with this function. Get the size, create your bitmaps, and then set them.

Example

// The code fragment below is from CMainFrame::OnCreate and shows 
// how to associate bitmaps with the "Bitmap" menu item. 
// Whether the "Bitmap" menu item is checked or unchecked, Windows 
// displays the appropriate bitmap next to the menu item. Both 
// IDB_CHECKBITMAP and IDB_UNCHECKBITMAP bitmaps are loaded 
// in OnCreate() and destroyed in the destructor of CMainFrame class. 
// CMainFrame is a CFrameWnd-derived class.

// Load bitmaps from resource. Both m_CheckBitmap and m_UnCheckBitmap
// are member variables of CMainFrame class of type CBitmap.
ASSERT(m_CheckBitmap.LoadBitmap(IDB_CHECKBITMAP));
ASSERT(m_UnCheckBitmap.LoadBitmap(IDB_UNCHECKBITMAP));

// Associate bitmaps with the "Bitmap" menu item. 
CMenu* mmenu = GetMenu();
CMenu* submenu = mmenu->GetSubMenu(4);
ASSERT(submenu->SetMenuItemBitmaps(ID_MENU_BITMAP, MF_BYCOMMAND, 
   &m_CheckBitmap, &m_UnCheckBitmap));
// This code fragment is taken from CMainFrame::~CMainFrame

// Destroy the bitmap objects if they are loaded successfully 
// in OnCreate().
if (m_CheckBitmap.m_hObject)
   m_CheckBitmap.DeleteObject();

if (m_UnCheckBitmap.m_hObject)
   m_UnCheckBitmap.DeleteObject();

Requirements

Header: afxwin.h

See Also

CMenu Class
Hierarchy Chart
GetMenuCheckMarkDimensions
SetMenuItemBitmaps