If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

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

Re: How to manage user messege sent by PostThreadMessage

Re: How to manage user messege sent by PostThreadMessage

about AfxEndThread - http://msdn.microsoft.com/en-us/libr...8VS.80%29.aspx
"Must be called from within the thread to be terminated." - so I used it.
and about message loop - do I need to write it by myself ? I thought that it's implemented in CWinThread. Could you write me a sample of that message loop, and where should I place it ? I need to execute some code in same time intervals - I doing it in my mainLoop()... Thank you for answers...

Re: How to manage user messege sent by PostThreadMessage

Re: How to manage user messege sent by PostThreadMessage

I do not remember already how to do that in MFC, but in WinAPI one must do something along the lines of:
BOOL rv;
MSG msg = {};
while (0 != (rv = GetMessage(&msg, 0, 0, 0)))
{
if (-1 == rv)
break;
TranslateMessage(&msg);
DispatchMessage(&msg);
}

The code in bold text is wrong. It is always wrong to do something extensive in InitInstance(). The purpose of InitiInstance) is initialization only, after which you should simply return TRUE so as to allow the built-in message loop to commence. Your code, on the other hand, traps the InitiInstance() function, by calling your mainLoop() function forever, and never allows InitInstance() to return. Thus, you block the built-in message loop from ever even starting.

Re: How to manage user messege sent by PostThreadMessage

Incidentally, it is always a bad architecture to use PostThreadMessage for posting messages to a thread that has any form of a visible window. If the thread hosts any form of a visible window, then the messages posted to it will inevitably be lost under very common circumstances.

* The Perfect Platform for Game Developers: Android
Developing rich, high performance Android games from the ground up is a daunting task. Intel has provided Android developers with a number of tools that can be leveraged by Android game developers.

* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.