PostThreadMessage

Started by
3 comments, last by steg 20 years, 9 months ago
Hi all, I am trying to use PostThreadMessage to post messages from one application to another (both standard MFC/C++ apps atm). I get the thread ID of one of the apps and use this in the PostThreadMessage call, now the application doesn''t get the message yet it is called correctly, I''m confused as to why ? Anybody any ideas ? Cheers, Steve

If it isn't working, take a bath, have a think and try again...

Advertisement
i''m pretty sure that PostThreadMessage puts msgs on the destination thread''s msg queue without tying it to an hWnd. so the message pump in the destination thread, assuming there is one, needs to be explicitly looking for the msg you posted since there is no hWnd to dispatch it to.

try using PostMessage instead if you''re trying to send a specific msg to a specific WindowProc. otherwise i think you''ll have to modify the destination thread''s msg pump to look for that particular msg.
Thanks,

SendMessage works fine, but I used PostThreadMessage as other apps I will be posting to don''t have a window, thus I guess they need to have their own message pump. I''m surprised the PostThreadMessage didn''t work when posting to a gui application though, the message defo got there but must be stuck in the applications message queue ?

Regards,
Steve

If it isn't working, take a bath, have a think and try again...

In the receiving application, make sure you''re calling GetMessage/PeekMessage like this:

MSG msg;
GetMessage(&msg,NULL /* NULL Window Handle */, 0, 0);
or
PeekMessage(&msg,NULL /* NULL Window Handle */, 0, 0, PM_REMOVE);


Specifying NULL as the window handle for Get/PeekMessage tells windows to give you ALL messages associated with the running thread.
daerid@gmail.com
Thanks Daerid,

I didn''t think though that you would have to specify/write your own message pump for the receiving application if it is gui - it has it''s own message pump - but doesn''t seem to be the case ?

Regards,
Steve

If it isn't working, take a bath, have a think and try again...

This topic is closed to new replies.

Advertisement