How to add MFC Dialog program menu

Copyright: please indicate the source! https://blog.csdn.net/ZouHuiDong/article/details/90546359

There are four general create MFC program types, namely a single document, multiple documents, based on dialog and top-level document. Which is only based on the type of dialog box does not own menu bar, if desired, can also be created manually, it is very simple.

How to add a menu?

Here to VS2012 example.

You must first create a menu
right in the resource view, select Add Resource
Here Insert Picture Description
selection menu resources, and then create, if there is a ready resource can be imported.
Here Insert Picture Description
Edited menu, and save.

Next to display the menu on the dialog box
to look at what the menu ID is to know which menu you want to add. (ID menu is best to change it, just for easy identification)
Here Insert Picture Description
found in the Menu Item Properties dialog box interface, select this menu. Note that not SystemMenu.
Here Insert Picture Description
Compile and run! ! Program has a menu.
Here Insert Picture Description

Add a menu in code

First create a menu, as with the above method
and then create a CMenu types of variables in the header file, called m_menu

CMenu m_menu;

Then add in the initialization function cpp file:

// 加载菜单资源
m_menu.LoadMenu(IDR_MENU1);
// 设置菜单
this->SetMenu(&m_menu);

The same effect.

Add a message response function to a menu

After receiving the setup menu click message, the response function is made.
Right-click options to set, click Add a message event handler
Here Insert Picture Description
to set various properties
Here Insert Picture Description
when received will be called when clicked. It recommended that you create before to modify ID option, if not modify the default digital, easy to distinguish and identify.

Guess you like

Origin blog.csdn.net/ZouHuiDong/article/details/90546359