Armentage
Armentage

Reputation: 12773

ValidateRect vs BeginPaint

From the MSDN documentation:

The BeginPaint function validates the entire client area.

The ValidateRect function 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.

Upvotes: 6

Views: 2395

Answers (1)

tenfour
tenfour

Reputation: 36906

It's not necessary. BeginPaint is used when you are validating the area because you handled it (painted it) in WM_PAINT.

ValidateRect is more to "cancel invalidation", usually after painting directly on the window without WM_PAINT or because something changed and you no longer want to be issued a pending WM_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_PAINT messages?), or wrong observations (for example you changed 2 things but this one got the attention instead of the other which is the actual fix).

Upvotes: 4

Related Questions