0

我想更新窗口(删除之前的绘图)并使用 x2,y2 的新值重新绘制。我从相机中得到 x2 和 y2,它们是手坐标,我想根据手坐标的新值绘制椭圆。我怎样才能做到这一点?

我尝试调用 Invalidate()、RedrawWindow() 和 UpdateWindow(),但它们似乎都不起作用。以下是我的一段代码。

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

}

}

4

1 回答 1

1
  1. 切勿将 UpdateWindow 放在 OnDraw 或 OnPaint 中。这将导致递归!
  2. 当您希望您的窗口应该反映新的内容时,您必须在识别更改的函数中调用 Invalidate。Invalidate 将导致调用新的 OnDraw 循环...因此,当识别出新手势时,获取它,为您的 doc/view 调用 Invalidate 设置新值。
  3. Ondraw 上有一个无限循环。这样做可以防止额外的 Windows 消息从队列中抽出并执行。所以你的程序是块。

也许您应该首先阅读一些标准教程,了解 Windows 输入和绘图的工作原理。

于 2013-09-30T07:09:00.547 回答