1. The menu is part of the window frame, if we want to import a custom menu, we can implement the following statement
Add the following snippet in the CMainFrame::OnCreate function
SetMenu(NULL);//将原本的菜单项去除menu;//新定义一个菜单对象menu.LoadMenu(IDR_MAINFRAME);//将ID为IDR_MAINFRAME菜单资源载入到menu对象中SetMenu(&menu);//将menu对象设为框架类对象的菜单menu.Detach();//断开菜单资源与菜单对象的关联
2. Generate a check mark menu item, which is implemented in the Framework class
GetMenu()->GetSubMenu(0)->CheckMenuItem(0,MF_BYPOSITION | MF_CHECKED);
3. Set the default menu item, which is bold in bold
GetMenu()->GetSubMenu(0)->SetDefaultItem(1,TRUE);/
4. Image Marker Menu item
GetMenu()->GetSubMenu(0)->SetMenuItemBitmaps(0,MF_BYPOSITION,&m_bitmap,&m_bitmap);
5. Do not use the menu settings
GetMenu()->GetSubMenu(0)->EnableMenuItem(1,MF_BYPOSITION | MF_DISABLED);
6. Right-click popup menu
In the Onrbuttondown function, add the following code:
CMenu menu; menu.LoadMenu(IDR_MENU1); CMenu *pPopup=menu.GetSubMenu(0); ClientToScreen(&point);// pointpoint.y,this);
7. Add a menu item, use AppendMenu () in the menu at the end of the submenu, InsertMenu () in the specified position with a submenu
menu1.AppendMenu(MF_STRING,ID_TEST1,"Test1");menu1.AppendMenu(MF_STRING,ID_TEST2,"Test2"); menu1.InsertMenu(1,MF_BYPOSITION|MF_STRING, (UINT)ID_TEST1,"ID_TEST1");
8. Delete Menu
Use the DeleteMenu (), Removemenu () function to delete menus/menu items at the specified location
9. Add right-click menu
Menu1. TrackPopupMenu (Tpm_rightbutton, Pt.x, Pt.y, this);
MFC Menu Actions