VC Custom Message response function PostMessage Usage Example _c language

Source: Internet
Author: User

This article describes the use of VC custom message response function PostMessage. Share to everyone for your reference. The following steps are implemented:

1. Add the following code in the Resource.h file to set a message of your own

Copy Code code as follows:
#define Wm_my_message Wm_user +//---------------------by tyds

2. The files in the ... view.h are added as follows:

Copy Code code as follows:
{{afx_msg (Cpostmessageview)
afx_msg void Ontydspostmessage ();

afx_msg/*lresult*/void OnMyMessage (/*wparam WPARAM, LPARAM lparam*/); -----by Tyds

}}afx_msg
Declare_message_map ()

3. Add the following code to the. view.cpp file

Copy Code code as follows:
Begin_message_map (Cpostmessageview, CView)
{{Afx_msg_map (Cpostmessageview)
On_command (Id_tyds_postmessage, Ontydspostmessage)
On_message (Wm_my_message, OnMyMessage)//Add message map---------------------by tyds
}}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 ()

void Cpostmessageview::ontydspostmessage ()
{
MessageBox ("Begin post message!");
PostMessage (Wm_my_message); Here PostMessage SendMessage Two The difference is
SendMessage (Wm_my_message); The PostMessage is sent out to return and the SendMessage is sent to wait until it is executed before returning
}

Message corresponding function
/*lpesult*/void cpostmessageview::onmymessage (/*wparam WPARAM, LPARAM lparam*/)/Note that the parameters here are not the same as the return values.
{

MessageBox ("Post msg finished!");
return 0;
}

I hope this article on the VC program for everyone to help.

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.