|Important||This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.|
Message Maps (MFC)
Handles WM_COMMAND messages generated by user menu selections or menu access keys.
Handle notification messages from child windows.
Handle WM_ messages, such as WM_PAINT.
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:
The ON_COMMAND macro is used to handle command messages generated by menus, buttons, and accelerator keys. Macros are available to map the following:
Update handler messages
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.
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.