This article describes the usage of postmessage, a custom message response function, in this article. Share it for your reference. The specific implementation steps are as follows:
1. Add the following code to the file to set your own message
2. Add the file in... as follows:
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... file
//{{AFX_MSG_MAP(CPostmessageView)
ON_COMMAND(ID_tyds_postmessage, Ontydspostmessage)
ON_MESSAGE(WM_MY_MESSAGE, OnMyMessage) //Add message mapping-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//}}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); //The two differences here are:
SendMessage(WM_MY_MESSAGE); //PostMessage returns when sent out, while SendMessage returns when sent out.
}
Message corresponding function
/*LPESULT*/void CPostmessageView::OnMyMessage(/*WPARAM wParam, LPARAM lParam*/) //Note whether the parameters here are required or not to determine them according to your own return value.
{
MessageBox("post msg finished!");
// return 0;
}
I hope this article will be helpful to everyone's VC programming.