VC custom message response function postmessage usage example
- 2020-04-02 02:56:03
- OfStack
This article illustrates the use of the VC custom message response function postmessage. Share with you for your reference. The specific implementation steps are as follows:
1. Add the following code to the resource-h file to specify a message of your own
#define WM_MY_MESSAGE WM_USER + 100 //---------------------by tyds
2. In... The file of view.h is added as follows:
//{{AFX_MSG(CPostmessageView)
afx_msg void Ontydspostmessage();
afx_msg void OnMyMessage(); //----- by tyds
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
3. In... Add the following code to the view.cpp file
BEGIN_MESSAGE_MAP(CPostmessageView, CView)
//{{AFX_MSG_MAP(CPostmessageView)
ON_COMMAND(ID_tyds_postmessage, Ontydspostmessage)
ON_MESSAGE(WM_MY_MESSAGE, OnMyMessage) //Add message mapping --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 differences
SendMessage(WM_MY_MESSAGE); //PostMessage is sent and returns, and SendMessage is sent and waits for execution before returning
}
Message corresponding function
void CPostmessageView::OnMyMessage() //Note that the parameters here may or may not depend on the return value as well as
{
MessageBox("post msg finished!");
// return 0;
}
Hope that this article described the VC programming for you to help.