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.