The book describes the implementation of rtti, dynamic creation, persistance, message mapping, and message routing. [1]
In particular, it is worth learning to establish a category-based record network.
1. MFC rules for message loops:
(1) if it is a common Windows message, it must flow from the derived class to the base class without going back.
(2) if it is a command message (wm_command), the path is very complex. The following summarizes the transmission of command messages.
The process in which MFC searches for corresponding message processing functions for command messages is: the command messages generated by user interface objects such as menus and toolbar are first sent to the Standard MFC Window Function of the main framework window; then, the Window Function transmits the command to the main framework window object of MFC, sends the command message, and matches the message according to the order in the table. If not, search for the message ing entry table of the base class. If not, search for the next object.
Retrieval path of table command messages
| Program type |
path |
| SDI (Single Document) |
current view → current document → document template → main Framework Window → application object |
| MDI (Multi-document) |
current view → current document → create document template → activity sub-Framework Window → main Framework Window → application object |
| dialog box |
current dialog box → parent window of the dialog box → application object |
If none of them are found, the default Windows message processing function ends the command message.
To improve message matching efficiency, MFC has a message buffer pool, which uses hash to search for messages, the pool can store information about 512 recently used message ing entry table items (note that you only need to add the entry table items, that is, two pointers ). The search process described above is performed only when it is not matched in the message buffer pool. [2]
Reference
[1] A Brief Introduction to MFC
[2] http://cc.seu.edu.cn/mm/cppsite/mfc/htms/kejian/07_2_6.htm