Display Icon or Bitmap at Menuitem

Discussion in 'MFC' started by cb02061, Jun 19, 2008.

  1. cb02061

    cb02061 New Member

    Joined:
    Apr 30, 2008
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    Hi,

    I have been developed a SDI application. I want to show icon or bitmap at menuitem.
    I already tested codes below, but it's not working???
    I got assertion failure error...
    I need help???

    Code:
    private:
    CBitmap m_bmpMenuFileNew; //File new bitmap (Checked and unchecked)
    CBitmap m_bmpMenuFileOpen; //File open bitmap (Checked and unchecked)
    
    
    
    int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
    {
    if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
    return -1;
    
    //Load the bitmap resource
    ASSERT( m_bmpMenuFileNew.LoadBitmap( IDB_MENU_NEW ) );
    ASSERT( m_bmpMenuFileOpen.LoadBitmap( IDB_MENU_OPEN ) );
    
    //Access the application menu
    CMenu* pMenu = GetMenu();
    ASSERT( pMenu );
    
    //Assign the icon
    ASSERT( pMenu->SetMenuItemBitmaps( ID_FILE_NEW, MF_BYCOMMAND,
    &m_bmpMenuFileNew, &m_bmpMenuFileNew ) );
    ASSERT( pMenu->SetMenuItemBitmaps( ID_FILE_OPEN, MF_BYCOMMAND,
    &m_bmpMenuFileOpen, &m_bmpMenuFileOpen ) );
    
    return 0;
    }
    
    
    CMainFrame::~CMainFrame()
    {
    if( m_bmpMenuFileNew.m_hObject )
    m_bmpMenuFileNew.DeleteObject();
    if( m_bmpMenuFileOpen.m_hObject )
    m_bmpMenuFileOpen.DeleteObject();
    }
     
    Last edited by a moderator: Jun 19, 2008

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice