正在运行的线程中的 cstatic 控件的 Redrawwindow

发布于 2024-11-27 12:32:46 字数 479 浏览 1 评论 0原文

我有一个 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"); 
}

我的问题是输出字符串结果相互覆盖;一旦有新的输出,文本就不会被删除。

我还应该做什么来解决这个问题?

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("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 ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

带刺的爱情 2024-12-04 12:32:46

我的猜测是,您正在主线程(GUI 线程)中创建窗口,然后从工作线程调用该窗口上的函数。这将违反规则,因为窗口与创建它们的线程具有亲和力。

确保所有使用窗口句柄的 API 调用都是从主线程进行的。请注意,SendMessage() 调用被编组到正确的线程上,但无论如何,出于性能原因,它们也最好从主线程发送。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文