MFC message ing mechanism

Source: Internet
Author: User

I. Message ing mechanism

1. Message response function: (for example, when the cdrawview Class responds, click the left button to press the message)

1) Declare the prototype of the message Response Function in the header file (drawview. h.

// {Afx_msg (cdrawview) // comment the macro
Afx_msg void onlbuttondown (uint nflags, cpoint point );
//} Afx_msg // annotation macro

Note:

The Declaration between the comment macros is displayed in gray in VC. The afx_msg macro declares a message response function.

2) perform message ing in the source file (drawview. cpp.

Begin_message_map (cdrawview, cview)
// {Afx_msg_map (cdrawview)
On_wm_lbuttondown ()
//} Afx_msg_map
// Standard printing commands
On_command (id_file_print, cview: onfileprint)
On_command (id_file_print_direct, cview: onfileprint)
On_command (id_file_print_preview, cview: onfileprintpreview)
End_message_map ()

Note:

Ing messages between macro begin_message_map () and end_message_map.

The macro on_wm_lbuttondown () associates the message wm_lbuttondown with its response function onlbuttondown. In this way, once a message is generated, the associated message response function is automatically called for processing.

Macro on_wm_lbuttondown () is defined as follows:

# Define on_wm_lbuttondown ()
{Wm_lbuttondown, 0, 0, 0, afxsig_vwp,
(Afx_pmsg) (afx_pmsgw) (void (afx_msg_call cwnd: *) (uint, cpoint) & onlbuttondown },

3) perform message response function processing in the source file. (The onlbuttondown function profile is automatically generated in drawview. cpp, as shown below)

Void cdrawview: onlbuttondown (uint nflags, cpoint point)
{
// Todo: add your message handler code here and/or call default
Cview: onlbuttondown (nflags, point );
}

Note:

It can be seen that when a message response is added, the above three items are modified. You can add a message processing code to the Message response function to complete the response and processing of the message.

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.