我正在使用MFC C ++并且我正在尝试使用来自Dlg类的PostThreadMessage向CWinThread发送消息,并且该消息未在线程类上处理
.H文件:
#define Message_Test_Id WM_USER + 1
class CTestMsg : public CWinThread
{
DECLARE_DYNCREATE(CTestMsg)
protected:
CTestMsg(); // protected constructor used by dynamic creation
virtual ~CTestMsg();
public:
virtual BOOL InitInstance();
virtual int ExitInstance();
protected:
afx_msg void OnTestMsg(WPARAM wParam, LPARAM lParam);//The Message
DECLARE_MESSAGE_MAP()
};
线程的.cpp:
BEGIN_MESSAGE_MAP(CTestMsg, CWinThread)
ON_THREAD_MESSAGE(Message_Test_Id,OnTestMsg)
END_MESSAGE_MAP()
....
void CTestMsg::OnTestMsg(WPARAM wParam, LPARAM lParam)
{
...
}
我正在尝试在Dlg类中发送消息:
CTestMsg *m_testMsg = (CTestMsg*)AfxBeginThread(RUNTIME_CLASS(CTestMsg),THREAD_PRIORITY_NORMAL, 10000, CREATE_SUSPENDED, NULL);
m_testMsg->PostThreadMessageW(Message_Test_Id, 0, 0);
为什么不处理邮件?谢谢! (抱歉我的英语不好)
答案 0 :(得分:2)
您正在使用CREATE_SUSPENDED
标志创建线程,要使其实际运行,您必须使用以下命令恢复它:
m_testMsg->ResumeThread();