0

I tried copying the CMenu Contents into CMFCPopupMenu using CMFCPopupMenu::Create() Method. All the CMenu Items are shown in PopUpMenu but Bitmaps are not Visible. I could not understand why.

When I insert CMenu in Toolbar the Bitmaps are displayed.

Below is my implemented code snippet from simple MFC Application.

    CMenu* TestCMenu = new CMenu();
    TestCMenu->CreateMenu();
        
    //creare  submenu's
    CMenu* subMenu1 = new CMenu();
    
    //make submenu popup
    subMenu1->CreatePopupMenu();
    

    HBITMAP hBitMap = (HBITMAP)LoadImage(NULL, L"SampleBitmap.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);

    subMenu1->AppendMenu(MF_STRING, ID_NEW, TEXT("New"));
    subMenu1->SetMenuItemBitmaps(ID_NEW, MF_STRING, CBitmap::FromHandle(hBitMap), CBitmap::FromHandle(hBitMap));

    subMenu1->AppendMenu(MF_STRING, ID_EXIT, TEXT("Exit"));
    subMenu1->SetMenuItemBitmaps(ID_EXIT, MF_STRING, CBitmap::FromHandle(hBitMap), CBitmap::FromHandle(hBitMap));

    SetMenu(TestCMenu);

CMenu in ToolBar

Below is my implemented code snippet using CMFCPopupMenu

CMFCPopupMenu* TestCMFCPopMenu = new CMFCPopupMenu;
TestCMFCPopMenu->SetAutoDestroy(FALSE);
TestCMFCPopMenu->Create(this, 1000,400, subMenu1->GetSafeHmenu());

using CMFCPopupMenu

In the 2nd image you see that Bitmaps are Not shown.

Could you please suggest what am I doing wrong?

latosvarun
  • 93
  • 6
  • `CMFCPopupMenu TestCMFCPopMenu = new CMFCPopupMenu;` Suspicious, you are mixing pointer and objects. There is no need to use `new`, just pay attention of lifetime of the ojects. – Tom Tom Jun 14 '23 at 13:03
  • @TomTom Sorry, I inserted my code wrong. Now the Question is corrected. Thanks !! – latosvarun Jun 14 '23 at 14:00
  • I don't see the full code, Can you format the question in stackoverflow, so that the bitmap Dialog, does not hidden the code partially – Tom Tom Jun 14 '23 at 16:16

0 Answers0