Is there something special about using BeginPaint/EndPain and not GetDC/ReleaseDC in response to WM_PAINT message?

StackOverflow https://stackoverflow.com/questions/7052411

Domanda

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?

È stato utile?

Soluzione

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.

Altri suggerimenti

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.

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top