To add a menu bar (CMenu) based on the MFC dialog box program

Source: Internet
Author: User

VS2013MFC the process of adding a menu bar to a dialog box, I have roughly divided these five steps.

First, add the menu to the resource View

In the resource view in workspace, on any of the folder icons , right-click the Insert (insert ) option and select menu in the popup dialog box , Click again , the New button , the menu will be added successfully , but it has not been completed, and can not be compiled , because the current menu space-time , at compile time will be erased.

Second, use the Menu editor to add menu bar and item

After the menu has been added successfully, the menu editor opens automatically, where you can add menu bars and menu items, which is relatively simple.

Three, load the menu into your dialog box

The first step is to add a menu item , which is actually added to your project , and then how to load the menu into your dialog box.

Open your newly added menu item and click "Project"--"Add Existing Item" here to select the existing class, which is the class of the dialog box for which you want to add a menu, for example,***dlg.cpp. And then determine.

Iv. adding code to the corresponding file

Open the dialog header file ***dlg.h, declaring the CMenu variable , such as M_menu;

Open the ***dlg.cpp file and add the following statement in ***dlg::oninitdlg ():

M_menu.loadmenu (IDR_MENU1); Idr_menu1 the ID of the menu you added , you can find it in the Menus folder of the resource view.

SetMenu (&m_menu);

This will be OK, debugging, the menu will already appear in the corresponding dialog box.

Use the wizard to generate a menu message response function

Select the Class Wizard under Project, select the class name***dlg.cpp, and in Object ID (B) Under the Commands tab, select the corresponding ID for each submenu item, and then double-click the command message in message (S) .

The dialog box will pop up and you can change the function name of the corresponding submenu item and click OK. The menu message response function is generated, adding the code you need.

To add a menu bar (CMenu) based on the MFC dialog box program

Related Article

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.