Do not call InvalidateRect()
or UpdateWindow()
from WM_PAINT
, or you will create an infinite loop of repaints.
Do not paint from the WM_TIMER
. It can be done (with GetWindowDC()
instead of BeginPaint()
but it isn't such a good idea.
Instead put the InvalidateRect()
in the WM_TIMER
and leave the drawing code in WM_PAINT
. You can optimize, as @typ1232 said in the comments, by creating the font only once, but that's not strictly necessary.
The UpdateWindow()
call should not generally be necessary, unless you are in a tight CPU loop and need to show the window just now: if the invalidation is done in a timer and the timeout is not too short you won't need it. But if your timeout is very short you can force the redraw calling UpdateWindow()
just after InvalidateRect()
.