简体   繁体   English

正在运行的线程中的静态控件的重绘窗口

[英]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) 我有一个CStatic控件,我想在运行时设置其文本(计算斐波那契数)

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("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. 我的猜测是您正在主线程(GUI线程)中创建窗口,但是随后从辅助线程在该窗口上调用函数。 That would be against the rules since windows have affinity to the thread on which they are created. 因为Windows与创建它们的线程具有亲和力,所以这将违反规则。

Make sure that all your API calls that use the window handle are made from the main thread. 确保所有使用窗口句柄的API调用都是从主线程进行的。 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. 请注意,将SendMessage()调用编组到正确的线程上,但是在任何情况下,出于性能原因,最好从主线程发送它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM