In MFC, The onwndmsg function is processed as follows:
1) First, determine whether a message has a message response function. For example, onlbuttondown () processes the message "left-click.
2) the judgment method is to find the desired message Response Function in the corresponding window class. Here, we take the project draw of MFC as an example. onwndmsg will search for it in cdrawtest. h to see on declare_message_map,
Whether there is a prototype Declaration of the corresponding message response function between two afx_msg comment macros, as follows:
//CDrawTest.h
Protected: // {afx_msg (cdrawview) afx_msg void onlbuttondown (uint nflags, cpoint point); // prototype declaration of the onlbuttondown () function //} afx_msgdeclare_message_map ()
Next, go to cdrawview. cpp and check whether there is a message ing macro between in_message_map () and end_message_map (), as shown below:
// Cdrawview. cppimplement_dyncreate (cdrawview, cview) begin_message_map (cdrawview, cview) // {afx_msg_map (cdrawview) on_wm_lbuttondown () // function onlbuttondown () in the message ing macro, //} afx_msg_map // standard printing commandson_command (id_file_print, cview: onfileprint) on_command (id_file_print_direct, cview: onfileprint) on_command (outputs, cview :: onfileprintpreview) end_message_map ()
3) if the message response function is found through steps 1) and 2, the response function is called to process the message.
If the message response function is not found in the subclass, the base class is processed.
4) through the above steps, MFC implements message ing to respond to messages.
5) implementation of the onlbuttondown () function: