Share via


Where to Find Message Maps

OverviewHow Do I

When you create a new skeleton application with AppWizard, AppWizard 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 AppWizard-supplied entries 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 AppWizard creates, you use ClassWizard 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, CView)
   //{{AFX_MSG_MAP(CMyView)
   ON_WM_MOUSEACTIVATE()
   ON_COMMAND(ID_EDIT_CLEAR_ALL, OnEditClearAll)
   ON_UPDATE_COMMAND_UI(ID_EDIT_CLEAR_ALL, OnUpdateEditClearAll)
   ON_BN_CLICKED(ID_MY_BUTTON, OnMyButton)
   //}}AFX_MSG_MAP
END_MESSAGE_MAP()

The message map consists of a collection of macros. Two macros, and , 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.

The message map also includes comments of the form

//{{AFX_MSG_MAP(CMyView)
//}}AFX_MSG_MAP

that bracket many of the entries (but not necessarily all of them). ClassWizard uses these special comments when it writes entries for you. All ClassWizard entries go between the comment lines.

When you use ClassWizard 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.