Mettre à jour uniquement le rectangle client

la programmation


Bonjour,

J’ai travaillé sur une application MFC multithread qui doit tracer un graphique sur un contrôle d’image. Tout semble

fonctionner correctement, mis à part le fait que le contrôle d’image ne se redessine pas lors de l’appel de la fonction Invalidate pour l’image

contrôle. La fenêtre entière est redessinée et un scintillement se produit si j’appelle Invalidate dans la boîte de dialogue. Des suggestions sur l’endroit où je

je me trompe ? J’ai essayé ceci mais cela n’a pas aidé : http://computer-programming-forum.com/82-mfc/1d8b6d604dd7c393.htm

Code:

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);
}
}

Solution 1

Je pense que le problème vient de l’accès à l’interface graphique depuis le thread de travail. Jetez un œil à cet article pour voir comment procéder correctement : Utilisation des threads de travail[^]

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.

Solution 3

http://Www.hotboat.com/frm/member.php?u=12894

コメント

タイトルとURLをコピーしました