Re: PostThreadMessage to a thread that has a modal dialog shown
"ultranet" <ultranet@discussions.microsoft.com> wrote in message
news:DD6B52F8-43B2-473A-BBC1-07CD48005DB3@microsoft.com...
PostThreadMessage(threadID, ...) returns 1 when modal dialog is shown,
but
message appears to be lost, because after i close the modal window, i
don't
get the message.
I will code to close modal windows before posting the message, but i find
this very strange. Any feedback is welcome.
It is not lost. It is simply ignored. :-)
Seriously, at the heart of a modal loop is code something like this:
while ( GetMessage(...) )
{
TranslateMessage(...);
DispatchMessage();
}
Thread messages have their hwnd member set to 0; So, your thread message is
gotten, but DispatchMessage(0 has nowhere to send it. To you it looks lost.
For that reason, some programmers maintain the handle to the "main" window
as a global variable. Rather than PostThreadMessage(), they post to the main
window.
A better solution, IMO, is to do this: Put up a thread-specific (not
global!) hook before you show the dialog. Have the hook insert a valid
window handle into the message structure where it is missing. Take down the
hook when the dialog is destroyed.
Regards,
Will
--
Regards,
Will
"I'm not ready to make nice, I'm not ready to back down ..."