From: Joseph M. Newcomer on
Thread messages can only be used to a UI thread which has no visible windows and which
uses only the MFC message pump in the secondary thread for its dispatching. You should
never, ever, create user-visible interface objects in a secondary thread (the rules about
what must be done and how it must be done are largely undocumented folklore, and a good
hint about their usability is the fact that nobody with any serious Windows experience
ever thinks this would be a good idea). A sure way to tell a beginner from an expert is
that a beginner tends to think about creating UI objects in secondary threads; an expert
would not consider this except under the most extreme circumstances.

I have no idea what you mean by "try to printf" since that is a waste of time; there is no
place printf can code. And you would not be using sprintf, or wsprintf because these are
obsolete and dangerous. Presumably you are using CString::Format.

To maintain counts like you are suggesting, you would create a modeless dialog owned by
the main GUI thread.
joe

On Mon, 14 Sep 2009 01:25:51 -0700 (PDT), "Jason .Y" <lin.yang.jason(a)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.
>
>Jason
Joseph M. Newcomer [MVP]
email: newcomer(a)flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
From: Jason .Y on
On 9月21日, 上午12时01分, Joseph M. Newcomer <newco...(a)flounder.com> wrote:
> Thread messages can only be used to a UI thread which has no visible windows and which
> uses only the MFC message pump in the secondary thread for its dispatching.  You should
> never, ever, create user-visible interface objects in a secondary thread (the rules about
> what must be done and how it must be done are largely undocumented folklore, and a good
> hint about their usability is the fact that nobody with any serious Windows experience
> ever thinks this would be a good idea).  A sure way to tell a beginner from an expert is
> that a beginner tends to think about creating UI objects in secondary threads; an expert
> would not consider this except under the most extreme circumstances.
>
> I have no idea what you mean by "try to printf" since that is a waste of time; there is no
> place printf can code.  And you would not be using sprintf, or wsprintf because these are
> obsolete and dangerous.  Presumably you are using CString::Format.
>
> To maintain counts like you are suggesting, you would create a modeless dialog owned by
> the main GUI thread.
>                                 joe
>
>
>
>
>
> On Mon, 14 Sep 2009 01:25:51 -0700 (PDT), "Jason .Y" <lin.yang.ja...(a)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.
>
> >Jason
>
> Joseph M. Newcomer [MVP]
> email: newco...(a)flounder.com
> Web:http://www.flounder.com
> MVP Tips:http://www.flounder.com/mvp_tips.htm

Thank you very much for your help. now I get to realize that's not a
good way to post thread message to another thread, which creates user-
visible interface objects. This strange question is by design.
First  |  Prev  | 
Pages: 1 2
Prev: CRepeatButton
Next: Knit picking