MFC message Response Mechanism
There are many resources in MFC, such as standard resources, menu resources, and toolbar resources. How do resources map message response and message?
Their process is:
A resource -- corresponding idnumber -- message ing -- declaration and implementation of the Response Function
The following uses the resource response in the toolbar as an example: (Multi-document applications)
1. Add an icon to the toolbar Resource (just click it), double-click it, and set its resource ID to id_myicon.
2. Add message ing to the. cpp file of the View class;
Find begin_message_map () and end_message_map ()
To add message ing statements.
On_command (id_myicon, onmyicon)
The first parameter is the resource ID, and the second parameter is the function name of the message response. To be consistent with the habit of MFC, we name itOnmyicon
3. Message response function declaration
Add member functions to the View classAfx_msgVoid onmyicon ();
4. Implementation of message Response Functions
Implement the onmyicon () function in the. cpp file of the View class;
Void cxxxxxview: onmyicon ()
{
MessageBox ("message ing successful! ");
}
The message response mechanism of menu resources is identical;
Windows OS includes the following messages:
1,Standard Windows messages: This message usesWM _Headers.
2. Notification Message
Notification messages are messages for standard Windows controls.
These controls include buttons, ComboBox, Textbox, ListBox, listview, Treeview, toolbar, and menu). Each type of message starts with a different string. (See Appendix)
3. Custom messagesProgrammers can also customize messages.
Appendix:
From msdn, we can see a lotOn _StartingMacroTo list some examples.
User button handlers (button)
Map entry |
Function prototype |
On_bn_clicked (<ID>, <memberfxn>) |
Afx_msg void memberfxn (); |
On_bn_disable (<ID>, <memberfxn>) |
Afx_msg void memberfxn (); |
On_bn_doubleclicked (<ID>, <memberfxn>) |
Afx_msg void memberfxn (); |
On_bn_hilite (<ID>, <memberfxn>) |
Afx_msg void memberfxn (); |
On_bn_paint (<ID>, <memberfxn>) |
Afx_msg void memberfxn (); |
On_bn_unhilite (<ID>, <memberfxn>) |
Afx_msg void memberfxn (); |
Combo box handlers (combo box)
Map entry |
Function prototype |
On_cbn_closeup (<ID>, <memberfxn>) |
Afx_msg void memberfxn () |
On_cbn_dblclk (<ID>, <memberfxn>) |
Afx_msg void memberfxn (); |
On_cbn_dropdown (<ID>, <memberfxn>) |
Afx_msg void memberfxn (); |
On_cbn_editchange (<ID>, <memberfxn>) |
Afx_msg void memberfxn (); |
On_cbn_editupdate (<ID>, <memberfxn>) |
Afx_msg void memberfxn (); |
On_cbn_errspace (<ID>, <memberfxn>) |
Afx_msg void memberfxn (); |
On_cbn_killfocus (<ID>, <memberfxn>) |
Afx_msg void memberfxn (); |
On_cbn_selchange (<ID>, <memberfxn>) |
Afx_msg void memberfxn (); |
On_cbn_selendcancel (<ID>, <memberfxn>) |
Afx_msg void memberfxn (); |
On_cbn_selendok (<ID>, <memberfxn>) |
Afx_msg void memberfxn (); |
On_cbn_setfocus (<ID>, <memberfxn>) |
Afx_msg void memberfxn (); |
Edit Control handlers (edit box)
Map entry |
Function prototype |
On_en_change (<ID>, <memberfxn>) |
Afx_msg void memberfxn (); |
On_en_errspace (<ID>, <memberfxn>) |
Afx_msg void memberfxn (); |
On_en_hscroll (<ID>, <memberfxn>) |
Afx_msg void memberfxn (); |
On_en_killfocus (<ID>, <memberfxn>) |
Afx_msg void memberfxn (); |
On_en_maxtext (<ID>, <memberfxn>) |
Afx_msg void memberfxn (); |
On_en_setfocus (<ID>, <memberfxn>) |
Afx_msg void memberfxn (); |
On_en_update (<ID>, <memberfxn>) |
Afx_msg void memberfxn (); |
On_en_vscroll (<ID>, <memberfxn>) |
Afx_msg void memberfxn (); |
Wait .................................... (See msdn)