I have been experimenting around with the device context and read quite a lot about it from the MSDN documentation. I have created a program which does some painting with double buffering and I ran into a small problem (Not really a problem, but curiosity from my side).
According to MSDN you should use BeginPaint and EndPaint whenever you are drawing on the window and releaseDC and getDC whenever you are performing drawing anywhere else.
I decided to try using GetDC and ReleaseDC anyway and I managed to get it to work Only issue is that the CPU usage during the lifetime of my program is extremely high. I am talking about 25% to 50% CPU usage.
I will post the code which I have in WM_PAINT. Would appreciate any tips for why this happens.
paintWindow is my own function that creates an offscreen DC, renders the frame and copies the content to the hdc. The code is not important since I am 100% positive it is not related to the problem I am experiencing.
The code below works flawlessly. No high CPU usage. Everything is cool.
CASE WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
paintWindow(hdc);
EndPaint(hWnd, &ps);
As soon as I try doing something like this:
hdc = GetDC(hWnd);
paintWindow(hdc);
ReleaseDC(hWnd, hdc);
The code still works flawlessly just as before, except the CPU usage is sky high. This is more or less an optimization problem and out of my own curiosity I would like to know what is the exact difference in the background and what should I do if I wanted to achieve the same thing as BeginPaint and EndPaind.