From the MSDN documentation:
The
BeginPaintfunction validates the entire client area.The
ValidateRectfunction should not be called if a portion of the
update region must be validated before the next WM_PAINT message is
generated.1
I’ve been programming with Win32 API for years, and I’ve never thought to call the ValidateRect function. A co-worker of mine today pointed that we were missing a call to ValidateRect, which fixed a bug we were having doing some high-speed animation using GDI (I know, an oxymoron)
Can someone tell me whether or not a call to ValidateRect is necessary after a BeginPaint/EndPaint pair? I have seen no documentation at MSDN that sheds light on this, and what documentation and examples I do see suggest that calling ValidateRect is not necessary.
It’s not necessary.
BeginPaintis used when you are validating the area because you handled it (painted it) inWM_PAINT.ValidateRectis more to “cancel invalidation”, usually after painting directly on the window withoutWM_PAINTor because something changed and you no longer want to be issued a pendingWM_PAINT.The fact that it fixed a bug likely means there’s something else going on, and this accidentally fixed it (maybe by reducing the number of
WM_PAINTmessages?), or wrong observations (for example you changed 2 things but this one got the attention instead of the other which is the actual fix).