设为首页 加入收藏

TOP

VC自定义消息postmessage用法(消息响应函数)
2014-10-28 11:30:06 来源: 作者: 【 】 浏览:83
Tags:定义 消息 postmessage 用法 响应 函数

  VC 自定义消息 postmessage用法
  1. 在 resource.h文件添加如下代码 定一个自己的消息
  #define 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 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); //这里 PostMessage SendMessage 两则区别是
  SendMessage(WM_MY_MESSAGE); //PostMessage 是发出去就返回 而SendMessage是发出去等到被 //执行了 在返回
  }
  消息相应函数
  /*LPESULT*/void CPostmessageView::OnMyMessage(/*WPARAM wParam, LPARAM lParam*/) //注意这里 的参数可要可不要 根据自己来定 返回值也一样
  {
  MessageBox("post msg finished!");
  // return 0;
  }


  编辑特别推荐:


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇考试大网校2010年全国计算机二级C.. 下一篇2011年计算机二级C语言考试备考冲..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: