gpt4 book ai didi

c++ - 后线程消息 C++ (CWinThread)

转载 作者:太空狗 更新时间:2023-10-29 21:39:41 24 4
gpt4 key购买 nike


我正在使用 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);

为什么消息没有被处理?谢谢! (抱歉我的英语不好)

最佳答案

您正在使用 CREATE_SUSPENDED 标志创建您的线程,要使其实际运行,您必须使用以下命令恢复它:

m_testMsg->ResumeThread();

关于c++ - 后线程消息 C++ (CWinThread),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32335955/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com