正在运行的线程中的 cstatic 控件的 Redrawwindow
我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我的猜测是,您正在主线程(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.