MFC Menu Actions

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.