VC中自定义消息

环境:vs.net + winXP SP3

一般步骤:

定义标识:

#define WM_CALCULATE  WM_USER+1

声明消息:

afx_msg LRESULT OnCalculate(WPARAM wParam,LPARAM lParam); 

关联:

BEGIN_MESSAGE_MAP(Cxxxclass, Cxxxbaseclass)

//{{AFX_MSG_MAP(Cxxxclass)

ON_MESSAGE(WM_CALCULATE,OnCalculate)

//}}AFX_MSG_MAP

END_MESSAGE_MAP()

消息定义:

 

LRESULT Cxxxclass::OnCalculate(WPARAM wParam,LPARAM lParam)

{

  ........

}

 

 

一般的自定义消息这样做就可以了,今天在搞多线程的一个例子的时发现当你的类派生自一个线程类CWinThread时就行不通了

其中关联的地方写成:

ON_THREAD_MESSAGE(Cxxxclass,Cxxxbasecalss);

MSDN解释:

ON_THREAD_MESSAGE must be used instead of ON_MESSAGE when you have a CWinThread class. User-defined messages are any messages that are not standard Windows WM_MESSAGE messages. There should be exactly one ON_THREAD_MESSAGE macro statement in your message map for every user-defined message that must be mapped to a message-handler function

 

我发单改这里还不行说LRESULT不成转成void,我于是把返回类型LRESULT改成void,运行成功,至于能否响应一会之后才知道

你可能感兴趣的:(thread,多线程,windows,function,user)