现在的位置: 首页 > 综合 > 正文

MFC的消息玄机–关于自定义消息

2018年11月01日 ⁄ 综合 ⁄ 共 1353字 ⁄ 字号 评论关闭

/////////////////////////////////////////////////////////////////////////////

 

// User extensions for message map entries

 

// for Windows messages

//窗口消息

#define ON_MESSAGE(message, memberFxn) \

 { message, 0, 0, 0, AfxSig_lwl, \

  (AFX_PMSG)(AFX_PMSGW) \

  (static_cast< LRESULT (AFX_MSG_CALL CWnd::*)(WPARAM, LPARAM) > \

  (memberFxn)) },

这个宏我们应该很常见也很常用,如果是我们自己普通定义的消息,即不使用RegisterWindowMessage注册到系统内,在添加到消息响应列表的时候使用这个宏。

 

// for Registered Windows messages

//注册的窗口消息

#define ON_REGISTERED_MESSAGE(nMessageVariable, memberFxn) \

 { 0xC000, 0, 0, 0, (UINT_PTR)(UINT*)(&nMessageVariable), \

  /*implied 'AfxSig_lwl'*/ \

  (AFX_PMSG)(AFX_PMSGW) \

  (static_cast< LRESULT (AFX_MSG_CALL CWnd::*)(WPARAM, LPARAM) > \

  (memberFxn)) },

而如果是我们或者系统使用RegisterWindowMessage注册的自定义消息,在添加到消息响应列表的时候使用这个宏,这时候如果使用上面的宏的话,是不管用的。

 

// for Thread messages

//线程消息

#define ON_THREAD_MESSAGE(message, memberFxn) \

 { message, 0, 0, 0, AfxSig_vwl, \

  (AFX_PMSG)(AFX_PMSGT) \

  (static_cast< void (AFX_MSG_CALL CWinThread::*)(WPARAM, LPARAM) > \

  (memberFxn)) },

这个宏用于新线程的自定义消息。

 

// for Registered Windows messages

//注册的线程消息

//呵呵,这里window的注释出现错误了。

#define ON_REGISTERED_THREAD_MESSAGE(nMessageVariable, memberFxn) \

 { 0xC000, 0, 0, 0, (UINT_PTR)(UINT*)(&nMessageVariable), \

  /*implied 'AfxSig_vwl'*/ \

  (AFX_PMSG)(AFX_PMSGT) \

  (static_cast< void (AFX_MSG_CALL CWinThread::*)(WPARAM, LPARAM) > \

  (memberFxn)) },

 这个宏用于新线程的注册到系统的自定义消息。

/////////////////////////////////////////////////////////////////////////////

抱歉!评论已关闭.