How to manage user messege sent by PostThreadMessage
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11

Thread: How to manage user messege sent by PostThreadMessage

Threaded View

  1. #1
    Join Date
    May 2006
    Posts
    21

    How to manage user messege sent by PostThreadMessage

    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
    Code:
    CReaderThread : public CWinThread {
    [...]
    afx_msg void OnMessageTest( WPARAM, LPARAM );
    protected:
    	DECLARE_MESSAGE_MAP()
    [...]
    }
    in CReaderThread.cpp
    Code:
    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::PreTranslateMessage(MSG* pMsg) {
    	if ( pMsg->message == WM_MESSAGE_TEST ) {
    		OnMessageTest( pMsg->wParam, pMsg->lParam );
    	}
    	return CWinThread::PreTranslateMessage(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.
    AragornX
    Last edited by aragornx; April 27th, 2010 at 04:23 AM. Reason: errors
    Share on Google+

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center