MFC message ing table and related macro definitions
Source: Internet
Author: User
MFC Technical Instructions:<See msdn mfc tno 5>In MFCSDK switch method to process Windows messages,By message ing table(Message map) and virtual function polymorphism to process the specified form message1. Declare a message ing table(Message map)Add a macro to the class that can process messages
Declare_message_map ()Note: MFC has a more detailed system overview. Here we only introduce several macro definitions. This macro provides three functions. : 1. Private Data member declaration Afx_messagemap_entry _ messageentries; Array 2. Data protection member statement Afx_message_map _ messagemap points to the _ messageentrie Array 3. Declare and define virtual protection member functions Getmessagemap () is used to obtain the _ messagemap address. Macro implementation and related member variables
Note that the class with message processing must be Csf-target derived from The class derived from cve-target can be processed at least. For wm_command messages, see Function implementation in cmdtarg. cpp Afx_static bool afxapi _ afxdispatch?msg () refers to the function for sending messages) The class must start Derived from the cwnd class Below is Member functions of cwnd and Its Derived classes for processing and sending messages Cwnd: onwndmsg (uint message, wparam, lparam, lresult * presult) 2. Add a message ing table header macro to the class implementation file. Begin_message_map (cmyclass, cbaseclass) Table not macro End_message_map () Add related macros to the table to filter and intercept messages. Otherwise, messages will flow to the Base Class 2.1 Processing standard in the derived structure of the message ing table. Window message macro (Find the macro definition in the header file of afxmsg _. h. ) Add in message ing table On_wm_xxx (XXX is the message name) IE: for example, processing in a form Wm_paint message Begin_message_map (cmywnd, cbasewnd) on_wm_paint () end_message_map () also requires a corresponding processing The wm_paint member function is in cmywnd. Standard The member function type corresponding to on_wm_xxx for Windows message processing can be found in Note: this function can be used Class winzard to complete 2.2 handling Macro of the message ing table for command messages (Find the macro definition in the header file of afxmsg _. h. ) The command message is generally generated by the menu command and the acceleration press 2.2.1. On_command On_command (cmd_id on1_func) afx_msg void on1_func (); note: Class winzard completed 2.2.2 On_command_ui On_command_ui (Region _id, onupdatecmduifunc) afx_msg void onupdatecmduifunc (ccmdui * pcmdui); note: Class winzard completed 2.2.3 On_command_range On_command_range (start_id, end_id, oncmdrangefunc) afx_msg void oncmdrangefunc (int id) Note: Class winzard completed 2.2.4 On_command_ui_range On_command_ui_range (start_id, end_id, onupdatecmduifunc) afx_msg void onupdatecmduifunc (ccmdui * pcmdui); note: Class winzard completed 2.2.5 On_command_ex On_command_ex (ID, oncmd) bool oncmd () returns True indicates that the message is processed; otherwise, the Message continues to flow in the message route. Similar to an exception. Note: Class winzard completed 2.3 Process User-defined message on_message (wm_userdefined, onmsg) hresult onmsg (wparam, lparam); User-defined message value can be defined Between wm_user-0x7fff 2.4 Process registered messages (System level) : Registerwindowmessage () Through this API You can register a message in the system and ensure that it is unique within the system. Macro on_registered_message (wm_registered_msg, onmsg) afx_msg hresult onmsg (wparam, lparam) that processes such messages ); 2.5 The notification message sent by the message control of the processing control to the parent form. The parent form can change the status or respond to some space at this time. Wm_notify message On_policy (wnotifycode, ID, memberfxn) Afx_msg void memberfxn (nmhdr * pnotifystruct, lresult * result ); On_policy_range (wnotifycode, ID, idlast, memberfxn) It can be used to process some standard spatial notification messages. You must use a macro to process custom control messages. On_control (wnotifycode, ID, memberfxn) on_control_range (wnotifycode, id1, Id2, memberfxn) 3 macro definition /////////////////////////////////// //////////////////////////////////////// /// window message map handling struct afx_msgmap_entry; // Declared below after cwnd Struct afx_msgmap {# ifdef _ afxdll Const afx_msgmap * (Pascal * pfngetbasemap )(); # Else Const afx_msgmap * pbasemap; # Endif Const afx_msgmap_entry * lpentries; }; # Ifdef _ afxdll # define declare_message_map ()/PRIVATE :/ Static const afx_msgmap_entry _ messageentries [];/ Protected :/ Static afx_data const afx_msgmap messagemap ;/ Static const afx_msgmap * Pascal _ getbasemessagemap ();/ Virtual const afx_msgmap * getmessagemap () const ;/ # Else # define declare_message_map ()/PRIVATE :/ Static const afx_msgmap_entry _ messageentries [];/ Protected :/ Static afx_data const afx_msgmap messagemap ;/ Virtual const afx_msgmap * getmessagemap () const ;/ # Endif # ifdef _ afxdll # define begin_message_map (theclass, baseclass )/ Const afx_msgmap * Pascal theclass: _ getbasemessagemap ()/ {Return & baseclass: messagemap ;}/ Const afx_msgmap * theclass: getmessagemap () const/ {Return & theclass: messagemap ;}/ Afx_comdat afx_datadef const afx_msgmap theclass: messagemap =/ {& Theclass: _ getbasemessagemap, & theclass: _ messageentries [0]};/ Afx_comdat const afx_msgmap_entry theclass: _ messageentries [] =/ {/ # Else # define begin_message_map (theclass, baseclass )/ Const afx_msgmap * theclass: getmessagemap () const/ {Return & theclass: messagemap ;}/ Afx_comdat afx_datadef const afx_msgmap theclass: messagemap =/ {& Baseclass: messagemap, & theclass: _ messageentries [0]};/ Afx_comdat const afx_msgmap_entry theclass: _ messageentries [] =/ {/ # Endif # define end_message_map ()/ {0, 0, 0, 0, afxsig_end, (afx_pmsg) 0 }/ };/
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.