[ad_1]
你好,
我一直在开发一个多线程 MFC 应用程序,需要在图片控件上绘制图形。 一切似乎
除了图片控件在调用图片的 Invalidate 函数时不会重绘之外,工作正常
控制。 如果我在对话框上调用 Invalidate,整个窗口将被重绘并发生闪烁。 关于我在哪里的任何建议
出问题了吗? 我已经尝试过这个但没有帮助: http://computer-programming-forum.com/82-mfc/1d8b6d604dd7c393.htm
代码:
C++
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); } }
解决方案1
我认为问题在于工作线程对 GUI 的访问。 看看这篇文章,看看如何做正确的方法: 使用工作线程[^]
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.
解决方案3
http://www.hotboat.com/frm/member.php?u=12894
[ad_2]
コメント