Freigeben über


Message Handling and Mapping

This article family describes how messages and commands are processed by the MFC framework and how you connect them to their handler functions.

In traditional programs for Windows, Windows messages are handled in a large switch statement in a window procedure. MFC instead uses message maps to map direct messages to distinct class member functions. Message maps are more efficient than virtual functions for this purpose, and they allow messages to be handled by the most appropriate C++ object — application, document, view, and so on. You can map a single message or a range of messages, command IDs, or control IDs.

WM_COMMAND messages — usually generated by menus, toolbar buttons, or accelerators — also use the message-map mechanism. MFC defines a standard routing of command messages among the application, frame window, view, and Active documents in your program. You can override this routing if you need to.

Message maps also supply a way to update user-interface objects (such as menus and toolbar buttons), enabling or disabling them to suit the current context.

For general information about messages and message queues in Windows, see Messages and Message Queues in the Windows SDK.

What do you want to know more about?

See Also

Reference

CWnd Class

CCmdTarget Class

Concepts

General MFC Topics

Other Resources

MFC Concepts