Device Context question

Hey,

In a tutorial I'm following, the following code is used for drawing a bitmap:

1
2
3
4
5
HDC hdc = 0;
HDC bitmHDC = 0;

hdc = BeginPaint(hWnd, &ps);
bitmHDC = CreateCompatibleDC(hdc);


First of all, why is a second DC needed here (why can't the "normal" one be used to draw bitmaps)?

Secondly, the second DC is removed in the tutorial with DeleteDC(bitmHDC); at the end of the WM_PAINT message. This is not done with the first DC. Why not? Is the tutorial wrong or is there a reason why the first DC shouldn't be removed?

Thank you,
Bv202

(Sorry if I've made a double post - there occured an error when I first tried to make this thread.)
Last edited on
First, a different DC is required because the bitmap and the first DC are two completely different things.

Second, did you see something like ReleaseDC(hdc)?
Hey,

First, a different DC is required because the bitmap and the first DC are two completely different things.

Can you explain this a bit?

Second, did you see something like ReleaseDC(hdc)?

Nope :(
The first device context is a device context of your applications client area(the area you can draw in), while the second device context is the device context of the bitmap itself.

There should be a call to EndPaint(), which effectively deletes the device context after a call to BeginPaint().

I suggest reading this:
http://winprog.org/tutorial/bitmaps.html
Last edited on
Hey,

Tyvm for the link, it's really helpful! :)
Topic archived. No new replies allowed.