Dexteroid CN
Dexteroid CN

Reputation: 81

How to repaint in CDC::OnDraw()?

I want to update the window (Delete the previous drawing) and redraw using the new values of x2,y2. I get x2 and y2 from a camera and they are hand coordinates, I want to draw the ellipse based on new values of the hand coordinates. How can i do that?

I tried to call Invalidate(), RedrawWindow() and UpdateWindow(), but none of them seem to work. Following is a chunk of my code.

     int x2,y2 // Global Variables (used to store coordinates of the hand)
     void GesturePipe()
      {
         x2=Hand.Coordinate.x;
         y2=Hand.Coordinate.y;

         // I get x2,y2 from a camera
      }


     void CLesson1View::OnDraw(CDC* pDC)
     {
    while(1)
      {
        GesturePipe();
        CLesson1Doc* pDoc = GetDocument();
        ASSERT_VALID(pDoc);
        if (!pDoc)
    return;
        COLORREF colorCircle= RGB(255,0,0); 
        pDC->Ellipse(0,0,(int) x2,(int) y2);
       //I intend to draw the skeleton of the hands so i would draw five lines,which  will get updated with each frame
        Invalidate(TRUE);
        UpdateWindow();

}

}

Upvotes: 0

Views: 1411

Answers (1)

xMRi
xMRi

Reputation: 15355

  1. Never place UpdateWindow in OnDraw or OnPaint. This will cause a recursion!
  2. When you want that your window should reflect new Contents, than you have to call Invalidate in the function that recognizes the changes. Invalidate will cause a new OnDraw cycle to be called... So when a new gesture is recognized, get it, set the new values for your doc/view call Invalidate.
  3. You have an infinite Loop on you Ondraw. Doing this will prevent that additional Windows Messages are pumped from the Queue and executed. So your program is blockes.

Maybe you should first read some standard tutorials how Windows Input and drawing works.

Upvotes: 1

Related Questions