0

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
    "*we have only RECT*" You can [`GetUpdateRgn`](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getupdatergn) inside `WM_PAINT`, just do it before `BeginPaint`. – dxiv Mar 23 '21 at 14:01

2 Answers2

1

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.

MSalters
  • 173,980
  • 10
  • 155
  • 350
  • 1
    Thank you for reply. It's alway the question of backwards compatibility. Of course. But who stops the Microsoft add something Like BeginPaintEx to deal with region... That is the question... – Alina Dzhanibekova Mar 23 '21 at 14:16
  • I would guess the number of developers Microsoft have working on WinAPI could be counted on the fingers of one hand. – Jonathan Potter Mar 23 '21 at 20:46
1

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.

IInspectable
  • 46,945
  • 8
  • 85
  • 181