Article ID: 142415 - Last Review: December 9, 2003 - Revision: 2.0 PRB: MFC Message Handler Not Called with PostThreadMessage()This article was previously published under Q142415 On This PageSYMPTOMS
When code uses the PostThreadMessage() Win32 function, the MFC message
handlers are not called.
CAUSE
When you call PostThreadMessage(), the message is placed in the thread's
message queue. However, because messages posted this way are not associated
with a window, MFC will not dispatch them to message or command handlers.
In order to handle these messages, override the PreTranslateMessage()
function of your CWinApp-derived class, and handle the messages manually.
RESOLUTION
The following code demonstrates how to call PostThreadMessage() in the
InitInstance() of the CWinApp-derived class using a single-threaded
application. The principle is the same for secondary threads except that
the code shown here would be put in your alternate CWinThread-derived
class. Visual C++ 4.2 does support handling messages posted to threads. For more information, see ON_THREAD_MESSAGE in the Visual C++ 4.2 documentation. NOTE: MFC worker threads do not have a message loop/pump associated with them so you must use a user-interface thread. Sample CodeREFERENCES
For more information on the CWinThread object, please see the following:
MFC Encyclopedia, Multithreading: Creating User-Interface Threads.
APPLIES TO
| Article Translations
|

Back to the top
