COMMUNICATING WITH WINDOWS
Windows communicates with your program by sending messages to it. Most of the drudgery of message handling is taken care of in an MFC application, so you don’t have to worry about providing a WndProc() function. The MFC enables you to provide functions to handle the individual messages that you’re interested in and to ignore the rest. These functions are referred to as message handlers or just handlers. In an MFC-based program, a message handler is always a member of one of your application’s classes.
The association between a particular message and a function in your program that is to service it is established by a message map, and each class in your program that handles Windows messages will have one. A message map is a table of member functions that handle Windows messages and the map bounded by a couple of macros. The start of a message map is indicated by a BEGIN_MESSAGE_MAP() macro, and the end is marked by an END_MESSAGE_MAP() macro. Each entry in the message map associates a member function with a particular message; when a given message occurs, the corresponding function is called. Only the messages that are relevant to a class appear in its message map.
A message map for a class is created by the MFC Application Wizard when you create a project, or by Class Wizard when you add a class that handles messages. Additions to, and deletions from, a message map are mainly managed by Class Wizard, but there are circumstances in which you need to modify ...
Get Ivor Horton's Beginning Visual C++ 2012 now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.