0

我需要反复重绘一个显示某种形式的连续分析的窗口。现在:

1)如果我在画完后在WM_PAINT中这样做,我基本上会杀死其他人的画,所以它不可用。

2)如果我在计时器中这样做,那就有点滞后了。

那么最好的方法是什么,以便频繁地重新绘制窗口,但是当操作系统忙于处理某些数据或通过绘制其他应用程序时,它会降低速率。我一直认为操作系统应该负责在进程之间分配 CPU 功率,让图形处于次要位置,以确保实际处理有足够的时间,但在 Windows 和 Mac 上看起来都不是这样。

4

1 回答 1

1

Typically you would create a timer and invalidate the window at each timer tick. If there is a lag, it could be that the update frequency is too high, or the processing performed in the paint method is too expensive.

Keep in mind that games with complex 3D scenes routinely achieve 60fps (and higher). So high framerate updates are certainly possible.

Note that under Windows, the WM_TIMER event is notoriously inconsistent. You may need to explore other high-resolution timers if you need more than ~1 second resolution.

On the Mac, you can create an NSTimer and call setNeedsDisplay:YES on your NSView. Something like this:

// in your init... method
NSTimer* repaintTimer = [NSTimer scheduledTimerWithTimeInterval:1.0
    target:self
    selector:@selector(timerTickHandler:)
    userInfo:nil
   repeats:YES];

// ...

-(void)timerTickHandler(NSTimer*)timer {
    [self.view setNeedsDisplay:YES];
}

The NSTimer in Cocoa is quite reliable, so the above should work just fine, even for quite fast updates.

If you need to update at frame-rate (ie. 25fps) have a look at the CVDisplayLink support. This is really only needed for video applications and the like.

于 2014-01-07T00:00:20.520 回答