Methods of user-defined message and its response function in MFC __ function

Source: Internet
Author: User

1. Customizing messages in the header file of the corresponding class

such as: #define Wm_result wm_user+1

2. Define the message response function in the header file, note: The return value of this function must be the LRESULT parameter must be WPARAM and lparam type.

This is because afx_msg void OnMyMessage (WPARAM, LPARAM); It is possible to define this method in VC6, but it is strictly required after VS2005 and so on.

To be defined as such, such as: afx_msg LRESULT displayresult (WPARAM wparam,lparam LPARAM);

3. Associating messages and response functions in. cpp

such as: On_message (wm_result,cdemo4view::D isplayresult)

Implementing a message response function

LRESULT Cdemo4view::D isplayresult (WPARAM wparam,lparam LPARAM)
{
CString str;
Double time = (double) LParam;
Str. Format ("%d prime number is%d,%f", primenumbers,g_result,time);
MessageBox (str);
return 0;
}

After the above steps can be.

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.