Re: CWinThread Can't Receive Custom Message in some case
On Mon, 14 Sep 2009 01:25:51 -0700 (PDT), "Jason .Y"
<lin.yang.jason@gmail.com> wrote:
Hi,I have come to meet a strange question in my application:
I have 2 Thread, which are both created by AfxBeginThread function
with a parameter of a derived class of CWinThread:
MsgCenterThread
MainTestThread
and the MainTestThread is always trying to post thread messages to
MsgCenterThread, The messages are defined as below:
#define APPMSG_SHOWDLG (WM_USER + 211)
#define APPMSG_DATA (WM_USER + 212)
The APPMSG_DATA is send 1 time per second, and the lParam is the count
of sending.
In case of APPMSG_SHOWDLG, the MsgCenterThread will create a CDialog
object and call the DoModal method.and in another case, The
MsgCenterThread will try to printf the sending count, which is
attached with the APPMSG_DATA as lParam .
The application seems to work fine,but once the MsgCenter has received
the APPMSG_SHOWDLG and show the Dialog, the MsgCenterThread can't
receive the APPMSG_DATA message for sometimes when I just clicked on
the Dialog very frequently.
By the way, My coding environment is :Windows XP + VS2005
Any suggestion will be appriciated.
PRB: PostThreadMessage Messages Lost When Posted to UI Thread
http://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