To show you what the effect of that 'InvalidateRect' is would like you to
make a few changes to your code.
Create a 'global' variable, initialize it with 0xFF0000 and use it as the
color for brush "d". After each "d" brush creation add something to that
color (I add 0x10 to the third byte, the FF / blue color)
On my puter I see the window change color when I move the mouse over it, or
when I enlarge the window. No color change when I shrink the window.
When I remove the 'InvalidateRect' inside the 'paint' event the whole window
still changes color when I move the mouse over it. But now take a look at
what happens when you enlarge the window ...
If you see the same as I do you see colored bands appear where you enlarged
the window, *but not where that window already existed*.
IOW, your code still *tries* to color the whole window, but due to only the
newly-added space being invalidated (by "the system") the drawing changes
only occur there. And likely you do not see any flickering (that you
programmed) *even though its still there* because there is too much change
going on - the border of the window moving and making place for some empty
Also notice that when you move the left border left or the top border up the
colored bands appear on the right or bottom. IOW : The moved part of the
window is /not/ redrawn at all. That is, as long as you do not invalidate
the whole window. Take a guess what happens when you also put an
'InvalidateRect' in the 'size' event. :-)
if you resize the window you will not see any flicker (repaint sended by the
if you move mouse inside the window, severe flicker will occurr (repaint
sended by me)
In neither case *you* are sending the repaint request. In the latter case
its send by "the system" as a result of it recognising that some visible
area has been marked as "changed" (that is what "invalidated" is supposed to
Suggestion : invalidate *a small part* of the window. Like a square of
10*10 pixels in the top-left corner.
Before you execute that, imagine what you think will happen. Also try to
reason why you think it would happen. And ? Does the result match your