vcmd5函数用法:VC 自定义消息 postmessage使用方法(消息响应函数)

VC 自定义消息 postmessage使用方法


1. 在 resource.h文件添加如下代码 定个自己消息
# WM_MY_MESSAGE WM_USER + 100 //---------------------by tyds

2.在...view.h文件添加如下:

//{{AFX_MSG(CPostmessageView)
afx_msg void Ontydspostmessage;

afx_msg /*LRESULT*/ void OnMyMessage(/*WPARAM wParam, LPARAM lParam*/); //----- by tyds

//}}AFX_MSG
DECLARE_MESSAGE_MAP

3.在...view.cpp文件添加如下代码
BEGIN_MESSAGE_MAP(CPostmessageView, CView)
//{{AFX_MSG_MAP(CPostmessageView)
ON_COMMAND(ID_tyds_postmessage, Ontydspostmessage)
ON_MESSAGE(WM_MY_MESSAGE, OnMyMessage) //添加消息映射---------------------by tyds
//}}AFX_MSG_MAP
// Standard pring commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePr)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePr)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrPreview)
END_MESSAGE_MAP


void CPostmessageView::Ontydspostmessage
{
MessageBox("begin post message!");
//PostMessage(WM_MY_MESSAGE); //这里 PostMessage SendMessage 两则区别是
SendMessage(WM_MY_MESSAGE); //PostMessage 是发出去就返回 而SendMessage是发出去等到被 //执行了 在返回

}

消息相应
/*LPESULT*/void CPostmessageView::OnMyMessage(/*WPARAM wParam, LPARAM lParam*/) //注意这里 参数可要可不要 根据自己来定 返回值也
{

MessageBox("post msg finished!");
// 0;
}
Tags:  excel自定义函数 vcpostmessage postmessage用法 vcmd5函数用法

延伸阅读

最新评论

发表评论