Reputation:
i'm using MFC C++ and I'm trying to send message to CWinThread using PostThreadMessage from Dlg Class and the message isn't handled on the thread class
.H file of the thread:
#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 of the thread:
BEGIN_MESSAGE_MAP(CTestMsg, CWinThread)
ON_THREAD_MESSAGE(Message_Test_Id,OnTestMsg)
END_MESSAGE_MAP()
....
void CTestMsg::OnTestMsg(WPARAM wParam, LPARAM lParam)
{
...
}
And I'm trying to send the message in the Dlg class:
CTestMsg *m_testMsg = (CTestMsg*)AfxBeginThread(RUNTIME_CLASS(CTestMsg),THREAD_PRIORITY_NORMAL, 10000, CREATE_SUSPENDED, NULL);
m_testMsg->PostThreadMessageW(Message_Test_Id, 0, 0);
why the message isn't handled? thanks! (sorry on my bad Engllish)
Upvotes: 3
Views: 1156
Reputation: 49976
You are creating your thread with CREATE_SUSPENDED
flag, to make it actually run you must resume it with:
m_testMsg->ResumeThread();
Upvotes: 2