Drawing to bitmaps has always been a bit of a pain, especially if you've got a custom bitmap format. The Windows GDI functions are pretty limited as to what they'll draw to (i.e. HDC's), but they're so nice and robust that you don't wanna have to roll your own.
My original idea was to have a bitmap constructor that takes an HDC, then copies the bits from the HDC into the bitmap. It worked, but it was awfully limited. Problem is, it's difficult to do bitmap-to-bitmap stuff, and mix it with GDI stuff. Drawing to a bitmap, then drawing else on top of what you drew later, for example, is pretty-much impossible.
My other idea was to put HDC support into the bitmap itself. This is what I did with my original bitmap objects for my old games. Something like this. . .
HDC hDC = B.CreateOutputDevice(); // copies the bits to the HDC
DrawAlignedText(hDC, Rectangle(0,0,100,100), String("Howdy"));
B.ReleaseOutputDevice(); // copies the bits from the HDC back to the bitmap
This works quite nicely, but it adds a bunch of member-data baggage to the bitmaps that's rarely used. My goal with the latest games is to make the often-used stuff as lightweight as possible. I finally came up with the idea to make a separate class that provides an HDC for the bitmap temporarily. It looks like the one above, but it's a separate class, so it's only got baggage as long as it's in use. . .
BitmapDC *pBmpDC = new BitmapDC(B); // copies the bits to the HDC
DrawAlignedText(pBmpDC->DC(), Rectangle(0,0,100,100), String("Howdy"));
delete pBmpDC; // copies the bits from the HDC back to the bitmap
I'm happy to report that it works wonderfully, which is why I'm reporting on it here :)