CMenu with Bitmap icon
-
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.
-
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.
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.
-
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.
-
I need a popup menu with an icon 16x16 on the left and the text on the right, for every menu item.
-
I need a popup menu with an icon 16x16 on the left and the text on the right, for every menu item.
-
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.
(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!
-
(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!
-
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!
-
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!
I done it!!!! I did so: 1) OnCreate i put this as you told me:
CMFCToolBar::AddToolBarForImageCollection(IDR_MAINFRAME_256);
-
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
-