Message Maps (MFC)

This section of the reference lists all message mapping macros and all CWnd message-map entries along with the corresponding member function prototypes:

Category

Description

WM_COMMAND Message Handler

Handles WM_COMMAND messages generated by user menu selections or menu access keys.

Child Window Notification Message Handlers

Handle notification messages from child windows.

WM_ Message Handlers

Handle WM_ messages, such as WM_PAINT.

User-Defined Message Handlers

Handle user-defined messages.

(For an explanation of the terminology and conventions used in this reference, see How to Use the Message Map Cross-Reference.)

Since Windows is a message-oriented operating system, a large portion of programming for the Windows environment involves message handling. Each time an event such as a keystroke or mouse click occurs, a message is sent to the application, which must then handle the event.

The Microsoft Foundation Class Library offers a programming model optimized for message-based programming. In this model, "message maps" are used to designate which functions will handle various messages for a particular class. Message maps contain one or more macros that specify which messages will be handled by which functions. For example, a message map containing an ON_COMMAND macro might look something like this:

BEGIN_MESSAGE_MAP(CMyDoc, CDocument)
   ON_COMMAND(ID_MYCMD, &CMyDoc::OnMyCommand)
END_MESSAGE_MAP()

The ON_COMMAND macro is used to handle command messages generated by menus, buttons, and accelerator keys. Macros are available to map the following:

Windows Messages

  • Control notifications

  • User-defined messages

Command Messages

  • Registered user-defined messages

  • User-interface update messages

Ranges of Messages

  • Commands

  • Update handler messages

  • Control notifications

Although message-map macros are important, you generally won't have to use them directly. This is because the Properties window automatically creates message-map entries in your source files when you use it to associate message-handling functions with messages. Any time you want to edit or add a message-map entry, you can use the Properties window.

Notes

The Properties window does not support message-map ranges. You must write these message-map entries yourself.

However, message maps are an important part of the Microsoft Foundation Class Library. You should understand what they do, and documentation is provided for them.

See Also

Concepts

Structures, Styles, Callbacks, and Message Maps