return 0;
...
}
return ::DefWindowProc(hwnd, message, wParam, lParam);
}
void Controller::Timer(int id) {
_timer.Kill();
_view.Step();
UpdateCanvas canvas(_hwnd);
_view.Update(canvas);
::InvalidateRect(_hwnd, 0, FALSE);
_timer.Set(50);
}
void Controller::Paint() {
PaintCanvas canvas(_hwnd);
_view.Paint(canvas);
}
The Update method of View is the workhorse of our program. It creates the image in the buffer. We then call InvalidateRectangle to force the repaint of our window (the last parameter, FALSE, tells Windows not to clear the previous image — we don't want it to flash white before every frame).
Here's the class View, with the three bitmaps.
class View {
public:
View(HINSTANCE hInst);
void SetSize(int cxNew, int cyNew) {
_cx = cxNew;
_cy = cyNew;
}
void Step() { ++_tick; }
void Update(Canvas& canvas);
void Paint(Canvas& canvas);
private: