开发者

Redrawwindow of a cstatic control within a running thread

I have a CStatic control that I would like to set its text at runtime (computing a Fibonacci number)

Class TXT:public CStatic
{
  private:
    CString m_str;
  public:
    SetText(const CString& str)
    {
       m_str=str;
       RedrawWindow();
    }
////other methods OnPaint etc 
}
//someclass that contains 
{
////....
TXT m_res;
///....

}
UINT threadProc(LPVOID lp)
{
   //computing Fibonacci
   p->m_res.SetText开发者_JAVA技巧("resultTXT"); 
}

My problem is the output string result overwrites each other; the text's not erased once a new output comes.

WHat else should I do to fix this problem ?


My guess is that you are creating the window in the main thread (the GUI thread), but then calling functions on that window from the worker thread. That would be against the rules since windows have affinity to the thread on which they are created.

Make sure that all your API calls that use the window handle are made from the main thread. Note that SendMessage() calls are marshalled onto the correct thread, but in any case, for performance reasons, they are also better to be send from the main thread.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜