M
Mrutyunjaya M
Guest
Hi - I have problem with receiving a message sent by PostThreadMessage. I'm posting message from main application class (CWinApp). I'm posting it to my class derived from CWinThread. Part of my thread class code:
CReaderThread.h
CReaderThread : public CWinThread {
[...]
afx_msg void OnMessageTest( WPARAM, LPARAM );
protected:
DECLARE_MESSAGE_MAP()
[...]
}
in CReaderThread.cpp
BEGIN_MESSAGE_MAP(CReaderThread, CWinThread)
ON_THREAD_MESSAGE( WM_MESSAGE_TEST, OnMessageTest )
END_MESSAGE_MAP()
BOOL CReaderThread::InitInstance() {
TRACE( _T("CReaderThread::InitInstance() START\r\n") );
if ( reader != NULL ) {
if ( start() == true ) {
mainLoop();
}
}
stop();
TRACE( _T("CReaderThread::InitInstance() STOP\r\n") );
AfxEndThread(0);
return TRUE;
}
void CReaderThread::mainLoop() {
long startTime = 0x00;
long endTime = 0x00;
long time2wait = 0x00;
MSG msg;
while ( CRealtime::getInstance()->isWorking() ) {
startTime = GetTickCount();
if ( PeekMessage(&msg, NULL, WM_USER, WM_USER, PM_NOREMOVE) ) {
TRACE( _T("RECEIVED message : %i\r\n"), msg.message);
}
[...]
::WaitForSingleObject( stopEvent->m_hObject, time2wait );
}
}
void CReaderThread::OnMessageTest( WPARAM wP, LPARAM lP ) {
TRACE( _T("Get Message wP=%i, lP=%i\r\n"), wP, lP );
return;
}
BOOL CReaderThread:reTranslateMessage(MSG* pMsg) {
if ( pMsg->message == WM_MESSAGE_TEST ) {
OnMessageTest( pMsg->wParam, pMsg->lParam );
}
return CWinThread:reTranslateMessage(pMsg);
}
I set breakpoints after PeekMessage(), in OnMessageTest() and in PreTranslateMessage() - nothing. Messages are lost. How to make my thread to receive sended messages?
Greetings.
Mrutyunjaya
Continue reading...
CReaderThread.h
CReaderThread : public CWinThread {
[...]
afx_msg void OnMessageTest( WPARAM, LPARAM );
protected:
DECLARE_MESSAGE_MAP()
[...]
}
in CReaderThread.cpp
BEGIN_MESSAGE_MAP(CReaderThread, CWinThread)
ON_THREAD_MESSAGE( WM_MESSAGE_TEST, OnMessageTest )
END_MESSAGE_MAP()
BOOL CReaderThread::InitInstance() {
TRACE( _T("CReaderThread::InitInstance() START\r\n") );
if ( reader != NULL ) {
if ( start() == true ) {
mainLoop();
}
}
stop();
TRACE( _T("CReaderThread::InitInstance() STOP\r\n") );
AfxEndThread(0);
return TRUE;
}
void CReaderThread::mainLoop() {
long startTime = 0x00;
long endTime = 0x00;
long time2wait = 0x00;
MSG msg;
while ( CRealtime::getInstance()->isWorking() ) {
startTime = GetTickCount();
if ( PeekMessage(&msg, NULL, WM_USER, WM_USER, PM_NOREMOVE) ) {
TRACE( _T("RECEIVED message : %i\r\n"), msg.message);
}
[...]
::WaitForSingleObject( stopEvent->m_hObject, time2wait );
}
}
void CReaderThread::OnMessageTest( WPARAM wP, LPARAM lP ) {
TRACE( _T("Get Message wP=%i, lP=%i\r\n"), wP, lP );
return;
}
BOOL CReaderThread:reTranslateMessage(MSG* pMsg) {
if ( pMsg->message == WM_MESSAGE_TEST ) {
OnMessageTest( pMsg->wParam, pMsg->lParam );
}
return CWinThread:reTranslateMessage(pMsg);
}
I set breakpoints after PeekMessage(), in OnMessageTest() and in PreTranslateMessage() - nothing. Messages are lost. How to make my thread to receive sended messages?
Greetings.
Mrutyunjaya
Continue reading...