Declare_message_map/begin_message_map () Usage

Source: Internet
Author: User

Declare_message_map ()

Description
Each ccmdtarget derived class in your program can provide a message map to process the message. Use the DECLARE_MESSAGE_MAP macro at the end of your class declaration. Then, the class member function is implemented. CPP file, add the BEGIN_MESSAGE_MAP macro to the macro entry for each message handler, and finally use the END_MESSAGE_MAP macro.
Attention:
If you define a member after DECLARE_MESSAGE_MAP, you must specify a new access type (public,private or protected) for them.
For more information about message maps and DECLARE_MESSAGE_MAP macros, see "Message Processing" and "Mapping Topics" in the Visual C + + Programmer's Guide.

Example:
Examples of Declare_message_map
Class Cmywnd:public CFrameWnd
{
Member declaration
Declare_message_map ()

};

Description

The function of the DECLARE_MESSAGE_MAP () macro is to add a message map to the class the necessary struct and function declarations, just add it once, where it is not important, just as the declarations of other ordinary functions in the class can be exchanged in order. The modifier of a function can also be determined by itself, following the general principle. For example, if you need to call the message response function outside of the class, you can define it as public.
======================================================
In some materials, there is such a text:
Declare_message_map ()
Description
Each ccmdtarget derived class in the user program must provide a message map to process the message. Use the DECLARE_MESSAGE_MAP macro at the end of the class definition. Next, you define the class member function. CPP file, use the BEGIN_MESSAGE_MAP macro, the list of macro entries for each user message handler function, and the END_MESSAGE_MAP macro.
Comments:
If any of the members are defined after declare_message_map, they must be assigned a new access type (public, private, protected).

I think his description is inappropriate, and my understanding is:

As long as there is: as long as the CCmdTarget (for all the base classes capable of message mapping) derived classes, there must be a message map to process the message, the end of the description file of the class has a DECLARE_MESSAGE_MAP macro, in the class's definition file has Begin_message_ Map macros and END_MESSAGE_MAP macros to handle user messages.

where Begin_message_map (parameter 1, parameter 2), Parameter 1 is the class name of the class, and Parameter 2 is the class name of the class base class.

where on_message (parameter 1, parameter 2), parameter 1 is the response message, parameter 2 is the function name that corresponds to the processing of the message.




/////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////

Begin_message_map () 1begin_message_map (Cpassapp, CWINAPP)
2 On_command (ID_HELP, CWinApp::OnHelp)
3end_message_map ()
These are macro definitions, not functions.
Add your message response function between Begin_message_map () and End_message_map (), adding a portal to each message handler function


Begin_message_map (Theclass, BaseClass)

Parameters:
Theclass Specifies the name of the class to which the message map belongs.
BaseClass Specifies the name of the base class for the Theclass.

Description
Use the BEGIN_MESSAGE_MAP macro to start the definition of your message map.
In the implementation file of the member function of your class (. CPP), start the message map with the BEGIN_MESSAGE_MAP macro, then add a portal for each message handler and end the message map with the END_MESSAGE_MAP macro.
The format for each message-map entry is as follows:
On_notification (ID, MEMBERFXN)
Where ID specifies the ID of the child window of the control that sent the notification, and MEMBERFXN specifies the name of the member function in the parent object that handles the notification.
The function prototype format of the parent object is as follows:
afx_msg void Memberfxn ();

The possible message map portals are as follows:
Map Portal When to send a message to a parent object
On_bn_clicked When the user clicks the button
On_bn_doubleclicked When the user double-clicks the button

For example:
1begin_message_map (Cpassdlg, CDialog)
2 On_wm_syscommand ()
3 On_wm_paint ()
4 On_wm_querydragicon ()
5//}}afx_msg_map
6 on_bn_clicked (IDOK, OnOK)
7 on_bn_clicked (IDCANCEL, OnExit)
8end_message_map ()

void Ctestdlg::onsyscommand (UINT NID, LPARAM LPARAM)

This function responds to commands in the System Control menu. (That is, the icon at the top left corner).

Onsyscommand:the framework calls this member function when the user selects a command from the Control menu, or when the U Ser selects the maximize or the Minimize button.

Other than that:

DoDataExchange: When UpdateData

OnInitDialog: The dialog class has been constructed, but the dialog box has not yet been displayed.

Onquerydragicon:the framework calls this member function by a minimized (iconic) window The does not has an icon defined For its class. The system makes the obtain the cursor to display while the user drags the minimized window.

Declare_message_map/begin_message_map () Usage

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.