I. Message ing mechanism
1. Message response function: (for example, when the cdrawview Class responds, click the left button to press the message)
1) Declare the prototype of the message Response Function in the header file (drawview. h.
// {Afx_msg (cdrawview) // comment the macro
Afx_msg void onlbuttondown (uint nflags, cpoint point );
//} Afx_msg // annotation macro
Note:
The Declaration between the comment macros is displayed in gray in VC. The afx_msg macro declares a message response function.
2) perform message ing in the source file (drawview. cpp.
Begin_message_map (cdrawview, cview)
// {Afx_msg_map (cdrawview)
On_wm_lbuttondown ()
//} Afx_msg_map
// Standard printing commands
On_command (id_file_print, cview: onfileprint)
On_command (id_file_print_direct, cview: onfileprint)
On_command (id_file_print_preview, cview: onfileprintpreview)
End_message_map ()
Note:
Ing messages between macro begin_message_map () and end_message_map.
The macro on_wm_lbuttondown () associates the message wm_lbuttondown with its response function onlbuttondown. In this way, once a message is generated, the associated message response function is automatically called for processing.
Macro on_wm_lbuttondown () is defined as follows:
# Define on_wm_lbuttondown ()
{Wm_lbuttondown, 0, 0, 0, afxsig_vwp,
(Afx_pmsg) (afx_pmsgw) (void (afx_msg_call cwnd: *) (uint, cpoint) & onlbuttondown },
3) perform message response function processing in the source file. (The onlbuttondown function profile is automatically generated in drawview. cpp, as shown below)
Void cdrawview: onlbuttondown (uint nflags, cpoint point)
{
// Todo: add your message handler code here and/or call default
Cview: onlbuttondown (nflags, point );
}
Note:
It can be seen that when a message response is added, the above three items are modified. You can add a message processing code to the Message response function to complete the response and processing of the message.