VS2010 the process of adding a menu bar to an MFC dialog box program
Recently looking at an MFC-written interface of the project code, in the code and interface has not seen how the menu control is added to the dialog box, so Baidu down. As a result, the other controls (button, and so on) are added differently;
The process of adding a menu bar to VS2010 's MFC dialog box is roughly divided into five steps.
First, add the menu to the resource view
In the Resource view in workspace, on the left side of the directory, right--Select the Insert Resource (insert Resource) option, select menu in the popup dialog box, then click the New button, the menu will be added successfully, But it's not done yet, and it's not going to compile, because now the menu space and time will be erased at compile time.
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 on "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
// 打开对话框头文件***Dlg.h,声明CMenu 变量,例如m_Menu;//打开***Dlg.cpp 文件,在***Dlg::OnInitDlg()中加入如下语句m_Menu.LoadMenu(IDR_MENU1); // IDR_MENU1为你加入的菜单的ID,在Resource视图的Menu文件夹下可以找到,如果代码提示中说IDR_MENU1没有定义的话(我遇到了这个问题,ID一样,但是提示没有定义,我是重新新建了一个工程就解决了)。SetMenu(&m_Menu);
If you do not have a wonderful problem, so it is OK, debugging, the menu has appeared in the corresponding dialog box.
Add a message response function for each item under the menu
First step: Right-click on the menu item and select Add Event Handler, as
The second step: for example, according to their own requirements, choose a good class, define the function of the name can be.
Follow the above steps to solve the menu problem in our dialog box.
The reference address is as follows: http://lishiqiang1988.blog.163.com/blog/static/41147912201382104631547/
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
VS2010 the process of adding a menu bar to an MFC dialog box program