Udostępnij za pośrednictwem


Where to Find Message Maps

 

The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.

The latest version of this topic can be found at Where to Find Message Maps.

When you create a new skeleton application with the Application Wizard, the Application Wizard writes a message map for each command-target class it creates for you. This includes your derived application, document, view, and frame-window classes. Some of these message maps already have the entries supplied by the Application Wizard for certain messages and predefined commands, and some are just placeholders for handlers that you will add.

A class's message map is located in the .CPP file for the class. Working with the basic message maps that the Application Wizard creates, you use the Properties window to add entries for the messages and commands that each class will handle. A typical message map might look like the following after you add some entries:

BEGIN_MESSAGE_MAP(CMyView, CFormView)
   ON_WM_MOUSEACTIVATE()
   ON_COMMAND(ID_EDIT_CUT, &CMyView::OnEditCut)
   ON_UPDATE_COMMAND_UI(ID_EDIT_CUT, &CMyView::OnUpdateEditCut)
   ON_BN_CLICKED(IDC_MYBUTTON, &CMyView::OnBnClickedMybutton)
   ON_WM_CREATE()
END_MESSAGE_MAP()

The message map consists of a collection of macros. Two macros, BEGIN_MESSAGE_MAP and END_MESSAGE_MAP, bracket the message map. Other macros, such as ON_COMMAND, fill in the message map's contents.

Note

The message-map macros are not followed by semicolons.

When you use the Add Class wizard to create a new class, it provides a message map for the class. Alternatively, you can create a message map manually using the source code editor.

See Also

How the Framework Searches Message Maps