仅更新客户端矩形 [英] Update only Client Rectangle

查看:103
本文介绍了仅更新客户端矩形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



我一直在研究需要在图片控件上绘制图形的多线程MFC应用程序。一切似乎



工作正常,除了图片控件不会重新调用图片的无效功能



控制。如果我在对话框上调用Invalidate,整个窗口将重新绘制并出现闪烁。有关我在哪里的建议



出错?我试过这个但是没有帮助: http://computer-programming-forum.com/82- mfc / 1d8b6d604dd7c393.htm



代码:



Hello,

I have been working on a multi-threaded MFC application that needs to plot a graph on a picture control. Everything seems

to work fine apart from the fact the picture control does not redraw on calling the Invalidate function for the picture

control. The whole window gets redrawn and flicker occurs if I call Invalidate on the dialog. Any suggestions on where I

am going wrong? I have tried this but it did not help: http://computer-programming-forum.com/82-mfc/1d8b6d604dd7c393.htm

Code:

DWORD WINAPI CDlg::WorkerThread(LPVOID lpVoid)
{
CDlg* appPtr = (CDlg*)lpVoid;
CStatic* pStatic = (CStatic*)appPtr->GetDlgItem(IDC_GRAPH_WINDOW);

while(true)
{
// Plotting graph
// Requires Update
appPtr->UpdatePoints(i);
pStatic->PostMessage(WM_PAINT);
}
}

推荐答案

我认为问题是来自工作线程的GUI访问。看看这篇文章,了解如何正确行事:使用工作线程 [ ^ ]



I think the problem is the acces of GUI from the worker thread. Take a look at this article to see how to do right way: Using Worker Threads[^]

Worker threads and the GUI II: Don't touch the GUI

That's right. A worker thread must not touch a GUI object. This means that you should not query the state of a control, add something to a list box, set the state of a control, etc.

Why?

Because you can get into a serious deadlock situation. A classic example was posted on one of the discussion boards, and it described something that had happened to me last year. The situation is this: you start a thread, and then decide to wait for the thread to complete. Meanwhile, the thread does something apparently innocuous, such as add something to a list box, or, in the example that was posted, calls FindWindow. In both cases, the process came to a screeching halt, as all threads deadlocked.


这篇关于仅更新客户端矩形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆