How do you post messages from a thread when none of your classes are CWinThread-derived?
BEGIN_MESSAGE_MAP(CMyClass, CDialog)
ON_MESSAGE(WM_MYMESSAGE, &CMyClass::OnMyMessage)
END_MESSAGE_MAP()
CMyClass::CMyClass()
{
m_pThread = AfxBeginThread((AFX_THREADPROC)MyLoop, NULL);
}
CMyClass::~CMyClass()
{
}
void CMyClass::MyLoop()
{
while(m_bContinue)
{
::PostMessageA(,WM_MYMESSAGE, NULL, NULL);
Sleep(1000);
}
}
void CMyClass::OnMyMessage()
{
}
I want to post a message from this loop that gets kicked off when a new thread starts. In the example, I want to post a message every second to the main thread so
OnMyMessage()
can do something interesting every second.
I keep getting told that
PostMessage
is not static so I can't call it from my thread. However, I think I read on CP that you have to use
PostMessage
to send messages between threads if the threads are not
CWinThread
.
=================================================
So I got as far as using
::PostMessage
thanks to CPallini, but now I have a new problem. How do I get the correct
HWnd
? I forced it to compile by setting a
NULL
. I don't know for sure if that's the problem but the message map macro failed. Something about not being able to convert between
void (_thiscall CMyClass::*)(void)
and
void(_thiscall CWnd::*)(WPARAM, LPARAM)
.
Please help!
Thanks.