Archived

This topic is now archived and is closed to further replies.

steg

PostThreadMessage

Recommended Posts

steg    390
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

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
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.

Share this post


Link to post
Share on other sites
steg    390
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

Share this post


Link to post
Share on other sites
daerid    354
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.

Share this post


Link to post
Share on other sites
steg    390
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

Share this post


Link to post
Share on other sites