Loading a bitmap next to a menu
Hi i'm trying to load a bitmap in a menu. I'm using this code, in the create function of the mainframe, but i'm not succesful:
bmp.LoadBitmap(IDB_BITMAP2);
this->GetMenu()->GetSubMenu(2)->SetMenuItemBitmaps(1,MF_BYPOSITION,&bmp,&bmp);
In the menu properties, the item number one, is checked.
what am i doing wrong?
thanks
[386 byte] By [
kfaday] at [2007-11-18 21:41:58]

# 1 Re: Loading a bitmap next to a menu
1. What does bmp.LoadBitmap(IDB_BITMAP2) return?
2. What do GetMenu(), GetSubMenu(2), SetMenuItemBitmaps(1,MF_BYPOSITION,&bmp,&bmp) return?
3. Have you seen the example in MSDN article "CMenu::SetMenuItemBitmaps ? Why not just to copy this code and use it?Example
// The code fragment below shows how to associate bitmaps with the
// "Test" menu item. Whether the "Test" 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.
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
// 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 "Test" menu item.
CMenu* mmenu = GetMenu();
CMenu* submenu = mmenu->GetSubMenu(3);
ASSERT(submenu->SetMenuItemBitmaps(ID_HELP_TEST, MF_BYCOMMAND,
&m_CheckBitmap, &m_UnCheckBitmap));
// ...
}
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();
}