One can use GetDC/ReleaseDC to draw in client area of window. But in response to WM_PAINT message one have to use BeginPaint/EndPaint. Is there something special about this?
A WM_PAINT message is issued when a part of the window needs to be updated. By specifying BeginPaint/EndPaint() you are telling gdi that you are actually doing that job. If you don't call BeginPaint() for the specified region, WM_PAINT messages will be generated for as long until someone actually updates it. The function gives you a DC just because it's convenient. Internally BeginPaint()/EndPaint() probably call GetDC()/ReleaseDC().
In contrast with GetDC and ReleaseDC you are telling GDI that you are now about to paint something onto the DC, without gdi requesting that you must.
BeginPaint
doesn't validate a handle, but rather the invalid region (those areas marked as invalid by calling InvalidateRect
/InvalidateRgn
). This is to tell the system, that the invalid region has been repainted, and no more painting is required, until some part of the window is invalidated again. A WM_PAINT
message is only generated, if the invalid region is non-empty. For reference, you should read About Painting and Drawing, and take it from there. –
Burrow Yes, sure. BeginPaint() retrieves the update region and automatically takes care of emptying it again. If you use GetDC() then you'll notice your program burning 100% cpu core, running the WM_PAINT handler over and over again because the update region was never cleared. You'd have to call ValidateRect() to avoid this.
GetUpdateRgn
can retrieve the current update region, and ValidateRect
(or ValidateRgn
) can be used to validate a rect/region. BeginPaint
and EndPaint
are just easier. –
Darcie BeginPaint
API call, that validates the update region (see GetUpdateRgn: "The BeginPaint function automatically validates the update region, so any call to GetUpdateRgn made immediately after the call to BeginPaint retrieves an empty update region."). –
Burrow BeginPaint function automatically sets the clipping region of the device context so if only part of your window have to be redrawn it wouldn't redraw the whole window.
© 2022 - 2024 — McMap. All rights reserved.