Looking specifically at a Windows Device Context, the answer to the primary question you're asking seems to be "yes and no".
A device context basically creates a mode in which drawing will be done -- i.e., at any given time, it'll have current settings for things like:
- Background color
- foreground color
- line width
- line pattern
- font
(and so on for quite a few more things).
Now, as far as there being a drawing surface: yes, I believe every device context always has a drawing surface attached to it. In the common case of a device context for a window, that drawing surface will be the part of the screen buffer where the window is displayed. In the case of a "compatible" device context (e.g., result from CreateCompatibleDC) it'll be a pretty useless drawing surface -- specifically, it's a single, monochrome pixel. It'll be set to either black or white, depending on whether the overall brightness level of whatever you draw to the DC exceeds a certain threshold or not (and no, offhand I don't remember the exact threshold).
This does have a (sort of) useful purpose though: in particular, it means that a DC is always "usable" -- there's never a situation in which drawing to a DC will fail just because there's no drawing surface attached. As an aid in maintaining this, there's no DeselectObject
function -- you can use SelectObject
to select a different bitmap into the device context (which will also deslect the original one) but there's no way to deselect one bitmap from the device context without selecting another into it -- so it always has a drawing surface attached.
At the same time, the default drawing surface for a compatible device context is so close to useless that it almost counts as not having a drawing surface attached at all.
Edit: I should also add that the default drawing surface that's selected into a compatible device context is a source of quite a few problems. In particular, when you're creating a compatible DC to do double-buffered drawing, you have to do something like this:
DC memDC = CreateCompatibleDC(windowDC);
BITMAP bmp = CreateCompatibleBitmap(WindowDC, sizeX, sizeY);
SelectObject(memDC, bmp);
If, however, you screw up ever so slightly and do this instead:
DC memDC = CreateCompatibleDC(windowDC);
BITMAP bmp = CreateCompatibleBitmap(memDC, sizeX, sizeY);
SelectObject(memDC, bmp);
...everything will succeed, and to some extent it'll all even work -- except that everything you draw via the compatible DC will end up in monochrome. This goes back to that one-pixel monochrome bitmap. Since the compatible DC has a monochrome bitmap selected into it by default, when you ask for a compatible bitmap, you'll get a monochrome bitmap of the specified size. In the first version you're asking for a bitmap compatible with the bitmap selected into the original DC, which will normally be the screen, so what you create will have the full color your screen is set for.