-
Updating Window
I've managed to cobble together my first Windows program. It implements the Game Of Life. It's all well and good - it starts off with an R-pentomino and animates correctly. Question is, it only animates when the mouse is moved over the window. How do I get it to always animate?
-
You can use the SetTimer function to create a timer. When the timer is triggered, you can call the InvalidateRect function. This will prompt Windows to post a WM_PAINT message to the window.
Code:
// At application startup, set up a function to fire once a second...
SetTimer(hwnd, ID_MYANIMATION, 1000, NULL);
// In your window procedure, handle WM_TIMER
case WM_TIMER:
InvalidateRect(hwnd, NULL, TRUE);
return 0;
-
Cheers! One more thing - all my variables pertinent to the window (including the two image buffers) are declared as static members in the window procedure. That doesn't seem right to me, but I can't see where else to do it.
-
I suggest you use UpdateWindow() as well.
It posts the paint msg (generated by InvalidateRect() ) directly to the apps msg que (not the OS msg que).
IMHO statics are acceptable as are globals (though globals can be confusing with many windows).
In C I define a structure to hold all the details of my windows. Keep then in a global array or linked list (and pass to functions a reference/pointer to the element I want).