WinAPI Is Region meaningless?

192 Views Asked by At

Could you explain me why WinAPI needs InvalidateRgn with its handle to the region to be added to the update region (hRgn) if we have only RECT during BeginPaint while processing WM_PAINT? Thanks in advance!

2

There are 2 best solutions below

2
MSalters On

Win32 API is about 30 years old; there's lots of code in there for backwards compatibility. There's a perfectly sane InvalidateRect.

Having said that, calling InvalidateRgn with bErase=TRUE will erase a non-rectangular area.

0
IInspectable On

Requiring the specific (complex) update region is an extremely rare use case. The system is optimized for the most common use case, where applications invalidate and track dirty areas of a window using rectangles. That's what you get when calling BeginPaint.

If you are in the rare situation where you need the update region, you can call GetUpdateRgn instead. Since BeginPaint validates the update region, you would have to call GetUpdateRegion before that.

Why does Windows not just go ahead and invent a BeginPaintEx API that returns the update region? Because adding an API is unbelievably expensive, and needs to be well justified. Adding a function that doesn't add any value (as in this case) is hard to justify.