Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. CMenu with Bitmap icon

CMenu with Bitmap icon

Scheduled Pinned Locked Moved C / C++ / MFC
graphicsalgorithmshelptutorialquestion
9 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Drakesal
    wrote on last edited by
    #1

    Hi i am searching many information about this, but i only find complex code. I simply need a context menu with icons. Now i post my code can you help me to complete?

    CMenu Menu;

    Menu.CreatePopupMenu();

    Menu.AppendMenuW(MF_STRING,ID_POPUP_1,(LPCTSTR)_T("Item 1"));

    Menu.AppendMenuW(MF_STRING,ID_POPUP_2,(LPCTSTR)_T("Item 2"));

    Menu.AppendMenuW(MF_STRING,ID_POPUP_3,(LPCTSTR)_T("Item 3"));

    theApp.GetContextMenuManager()->ShowPopupMenu(Menu, point.x, point.y, this, TRUE);

    I have seen on MSDN i have to use this:

    // 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));

    But i think my situation is more easy than example, but maybe i have problems to merge the two code parts, please can you help me i don't think take you more time. Thanks very much.

    L M 2 Replies Last reply
    0
    • D Drakesal

      Hi i am searching many information about this, but i only find complex code. I simply need a context menu with icons. Now i post my code can you help me to complete?

      CMenu Menu;

      Menu.CreatePopupMenu();

      Menu.AppendMenuW(MF_STRING,ID_POPUP_1,(LPCTSTR)_T("Item 1"));

      Menu.AppendMenuW(MF_STRING,ID_POPUP_2,(LPCTSTR)_T("Item 2"));

      Menu.AppendMenuW(MF_STRING,ID_POPUP_3,(LPCTSTR)_T("Item 3"));

      theApp.GetContextMenuManager()->ShowPopupMenu(Menu, point.x, point.y, this, TRUE);

      I have seen on MSDN i have to use this:

      // 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));

      But i think my situation is more easy than example, but maybe i have problems to merge the two code parts, please can you help me i don't think take you more time. Thanks very much.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      According to the documentation[^], the bitmaps are just used to indicate the item is selected or not. The MSDN sample shows you how to add the two bitmaps to your menu items. When you say you just want icons, do you mean without any text? If so you need to look at http://msdn.microsoft.com/en-us/library/kb145b0a.aspx[^], for the options to set up individual menu items.

      D 1 Reply Last reply
      0
      • L Lost User

        According to the documentation[^], the bitmaps are just used to indicate the item is selected or not. The MSDN sample shows you how to add the two bitmaps to your menu items. When you say you just want icons, do you mean without any text? If so you need to look at http://msdn.microsoft.com/en-us/library/kb145b0a.aspx[^], for the options to set up individual menu items.

        D Offline
        D Offline
        Drakesal
        wrote on last edited by
        #3

        I need a popup menu with an icon 16x16 on the left and the text on the right, for every menu item.

        L _ 2 Replies Last reply
        0
        • D Drakesal

          I need a popup menu with an icon 16x16 on the left and the text on the right, for every menu item.

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          I gave you the link to the documentation, you just need to follow the instructions.

          1 Reply Last reply
          0
          • D Drakesal

            I need a popup menu with an icon 16x16 on the left and the text on the right, for every menu item.

            _ Offline
            _ Offline
            _Flaviu
            wrote on last edited by
            #5

            Have you seen this solution ?Bitmap Menu[^]

            1 Reply Last reply
            0
            • D Drakesal

              Hi i am searching many information about this, but i only find complex code. I simply need a context menu with icons. Now i post my code can you help me to complete?

              CMenu Menu;

              Menu.CreatePopupMenu();

              Menu.AppendMenuW(MF_STRING,ID_POPUP_1,(LPCTSTR)_T("Item 1"));

              Menu.AppendMenuW(MF_STRING,ID_POPUP_2,(LPCTSTR)_T("Item 2"));

              Menu.AppendMenuW(MF_STRING,ID_POPUP_3,(LPCTSTR)_T("Item 3"));

              theApp.GetContextMenuManager()->ShowPopupMenu(Menu, point.x, point.y, this, TRUE);

              I have seen on MSDN i have to use this:

              // 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));

              But i think my situation is more easy than example, but maybe i have problems to merge the two code parts, please can you help me i don't think take you more time. Thanks very much.

              M Offline
              M Offline
              Maximilien
              wrote on last edited by
              #6

              (disclaimer, I've not tried it on a popup menu; only regular menu). The simplest way is to use CMFCToolBar::AddToolBarForImageCollection. You create a dummy toolbar with all the images you want to use and call the above static method and the images will automagically be added to the menus.

              I'd rather be phishing!

              D 1 Reply Last reply
              0
              • M Maximilien

                (disclaimer, I've not tried it on a popup menu; only regular menu). The simplest way is to use CMFCToolBar::AddToolBarForImageCollection. You create a dummy toolbar with all the images you want to use and call the above static method and the images will automagically be added to the menus.

                I'd rather be phishing!

                D Offline
                D Offline
                Drakesal
                wrote on last edited by
                #7

                Can you show me in code if is possible?

                M 1 Reply Last reply
                0
                • D Drakesal

                  Can you show me in code if is possible?

                  M Offline
                  M Offline
                  Maximilien
                  wrote on last edited by
                  #8

                  It is quite simple, just create a new toolbar with the images you need (with the same ID as your menu ID). and call

                  // Load menu items images(not placed on the standard toolbars):
                  CMFCToolBar::AddToolBarForImageCollection(IDR_MENU_IMAGES);

                  at the end of the "OnCreate" of the mainframe (in case of a MFC document). Have a look at the C++/MFC samples available on MSDN. http://www.microsoft.com/en-us/download/details.aspx?id=5718[^] There are examples of that in the: "VisualStudioDemo", "NewControls" samples. (among others).

                  I'd rather be phishing!

                  D 1 Reply Last reply
                  0
                  • M Maximilien

                    It is quite simple, just create a new toolbar with the images you need (with the same ID as your menu ID). and call

                    // Load menu items images(not placed on the standard toolbars):
                    CMFCToolBar::AddToolBarForImageCollection(IDR_MENU_IMAGES);

                    at the end of the "OnCreate" of the mainframe (in case of a MFC document). Have a look at the C++/MFC samples available on MSDN. http://www.microsoft.com/en-us/download/details.aspx?id=5718[^] There are examples of that in the: "VisualStudioDemo", "NewControls" samples. (among others).

                    I'd rather be phishing!

                    D Offline
                    D Offline
                    Drakesal
                    wrote on last edited by
                    #9

                    I done it!!!! I did so: 1) OnCreate i put this as you told me:

                    CMFCToolBar::AddToolBarForImageCollection(IDR_MAINFRAME_256);

                    1. in Contextmenu i add these lines:

                      CMFCPopupMenu* PopupMenuFolders = new CMFCPopupMenu();

                      //Mi serve controllare prima che esce il menu per eventualmente eliminare voci del menu non permesse.
                      CheckWhatCanIDo(ExtractFullTreePath(htSelectedTreeItem),MainComputerinfo.szSid,m_bUserAuthorizations);

                      PopupMenuFolders->InsertItem(CMFCToolBarMenuButton(ID_POPUP_FOLDERS_TREE_1, NULL, 0, _T("Item 1")));

                      PopupMenuFolders->InsertItem(CMFCToolBarMenuButton(ID_POPUP_FOLDERS_TREE_2, NULL, 1, _T("Item 2")));

                      PopupMenuFolders->InsertItem(CMFCToolBarMenuButton(ID_POPUP_FOLDERS_TREE_3, NULL, 2, _T("Item 3")));

                      PopupMenuFolders->Create(this, point.x, point.y, NULL);

                    So you use directly the Toolbar Images. Thanks all ;) Giovanni

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups