Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between GetDC() and BeginPaint()

I am working on Win32 UI. I want to know the difference Between GetDC and BeginPaint. When to Use which API and when not to use which API.

like image 369
Umesha MS Avatar asked Apr 30 '11 10:04

Umesha MS


2 Answers

GetDC() is not a substitute for Begin+EndPaint(). If you try, you'll find that your UI thread starts to burn 100% cpu core and your WM_PAINT handler getting called over and over again.

The big one is BeginPaint(), it clears the update region of the window. The value of PAINTSTRUCT.rcPaint. WM_PAINT is generated as long as the window has a dirty rectangle, created by an InvalidateRect() call by either the window manager or your program explicitly calling it. BeginPaint() clears it.

like image 66
Hans Passant Avatar answered Sep 28 '22 02:09

Hans Passant


BeginPaint is intended to be called only in response to WM_PAINT message. The device context obtained by it points to the invalidated (to-be-redrawn) area of the window. It should be then released using EndPaint.

GetDC can be called at any time. The device context obtained by it points to the whole client area of the window. To release it, you should call ReleaseDC.

like image 22
Xion Avatar answered Sep 28 '22 01:09

Xion