Re: CWinThread Can't Receive Custom Message in some case

Tech-Archive recommends: Fix windows errors by optimizing your registry



On 9月14日, 下午9时15分, "Doug Harrison [MVP]" <d....@xxxxxxxx> wrote:
PRB: PostThreadMessage Messages Lost When Posted to UI Threadhttp://support.microsoft.com/kb/183116

Also, if you're going to use thread messages, you can start numbering them
anywhere. Basing them on WM_USER is kinda strange :) For more on what the
message ranges mean, see:

Which message numbers belong to whom?http://blogs.msdn.com/oldnewthing/archive/2003/12/02/55914.aspx

That said, it's a good idea to keep the UI all in one thread, your
program's main thread. Presumably, it has some sort of window that could be
the target for all your custom WM_APP-based messages. If not, you can
create a hidden message-only window for this purpose.

--
Doug Harrison
Visual C++ MVP

Thank you very much for your help!

but I still have a question:according to the article <PRB:
PostThreadMessage Messages Lost When Posted to UI Thread>, all the
message send to a UI thread by PostThreadMessage would be lost when
the UI Thread is showing a modal dialog box.

"When an UI thread is involved in modal behavior, the thread pumps
messages in a message loop internal to the modal system rather than in
the thread's main message loop. Messages that are posted to a window
can still be dispatched to the window procedure of the target window,
because the messages are associated with a window. However, thread
messages need to be handled directly by the message loop, because they
cannot be automatically dispatched elsewhere. Since the secondary
message loop does not know about the thread message, it will be
dropped."

but in fact,the message won't be lost if I don't manipulate the dialog
very frequently. then I'm comfused:why message send by
PostThreadMessage would not get lost in this situation?As the message
loop internal to the modal dialog is the primary message loop.the
thread message should be drop.

----
Jason
.



Relevant Pages

  • Re: CWinThread Cant Receive Custom Message in some case
    ... PostThreadMessage Messages Lost When Posted to UI Thread>, ... the thread's main message loop. ... Messages that are posted to a window ...
    (microsoft.public.vc.mfc)
  • Re: PostThreadMessage and Lost Messages
    ... This is known and documented behavior for PostThreadMessage, ... "Messages sent by PostThreadMessage are not associated with a window. ... thread is in a modal loop, ... will be lost. ...
    (microsoft.public.vc.mfc)
  • Re: WM_USER based messages lost while scrolling
    ... Scrolling is an example of a modal loop. ... You can't PostThreadMessage to a GUI thread that has user-visible elements. ... you should consider using WM_APP messages or better still Registered Window ... Whats happening is that this message is getting lost. ...
    (microsoft.public.vc.mfc)
  • Re: PostThreadMessage and Lost Messages
    ... I got around this problem by embedding a window into each CWinThread ala ... Conversation: PostThreadMessage and Lost Messages ... your application's message loop is bypassed for generic ones inside ... the CWinApp derived class, but at a different level like in the ...
    (microsoft.public.vc.mfc)
  • Re: Problem with PostThreadMessage with date time activex control
    ... first-hand (which is what David W. was referring to). ... Messages sent to a UI thread through PostThreadMessage are lost if the ... resizes the window or if the window is a modal dialog box. ...
    (microsoft.public.vc.mfc)