Alina Dzhanibekova
Alina Dzhanibekova

Reputation: 1

WinAPI Is Region meaningless?

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!

Upvotes: 0

Views: 218

Answers (2)

IInspectable
IInspectable

Reputation: 51512

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.

Upvotes: 1

MSalters
MSalters

Reputation: 180235

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.

Upvotes: 1

Related Questions