Windows communicate with the application by sending messages. There are many Windows messages and each message is represented by a unique integer value.In WINDOWS.H there are standard names for these messages.
There are some common Windows messages like:-
Messages are always accompanied by other values that contain additional,related in formation.This information includes things like cursor or mouse coordinates etc.Windows interacts with your programs through messages.Specifically each time when event occurs a message is sent to program which identifies the event. As there are large number of messages so it not necessary for the program to respond allthe messages so MFC has a default message handler. In a normal Windows program your program's window procedure receives each message and also any additional information which is related to that message .Inside the window procedure,a large switch statement determines what type of message has been received and then processes it accordingly.While using MFC responding messages is much easier.
MFC provides a set of predefined message handler functions that your program may implement. If your program implements one of these handlers then that function will be called whenever its associated message is received.When a message has an additional information associated to it this information will be passed to message handler as an argument.
To respond to a message ,your program must perform these three steps:-
1. The message macro corresponding to the message must be added to your program's message map.
2. The prototype for the message handler must be added to the window class that will process the message.
3. Implement the message handler associated with the message.
MFC message macros have the same name as standard window messages,except that they all begin with ON_ and end with a set of parentheses.There is one exception to this rule: the WM_COMMAND message uses ON_COMMAND for its message macro. This is because WM_COMMAND is a rather special windows message and it requires unique treatement by MFC.
Here are some MFC message macros:-
ON_WM_CHAR,ON_WM_PAINT,ON_WM_MOVE,ON_WM_CLOSE,ON_W M_LBUTTONUP,ON_WM_LBUTTONDOWN,ON_WM_COMMAND,ON_WM_ SIZE. To add a message macro to your message map,simply include it between BEGIN_MESSAGE_MAP and END_MESSAGE_MAP.
Each message that your program responds to must be associated with a message handler. All message handlers are members of the CWND class, and may be overridden by your program. As a general rule name of the message handler is constructed using the name of the message preceded by ON. For example , the handler for WM_CHAR IS OnChar(),the handler for WM_LBUTTONDOWN is OnLButtonDown().
To respond to the message one must add the message handler to the window class that your program defines and that is done by including its prototype in the class declaration.
Implementing Message Handlers
Implementing message handlers depends on two things:-
1.Nature of the message.
2.Meaning of the message for your program.