I remember this being very difficult to figure out at first (because you can't just use CreateCompatibleBitmap on your shiny new compatible device context) but I'm using a lot of memory-based bitmaps at the moment for screen buffers.
I don't know what the original question was, but here's a general solution. (I'll skip a wrapper prog.)
HBITMAP hbmImage;
HWND hWnd;
void CreateBitmap(void) {
HDC wDC = GetDC(hWnd);
// create a bitmap compatible to the screen
hbmImage = CreateCompatibleBitmap(wDC,30,30);
ReleaseDC(hWnd,wDC);
}
void DrawBitmap(int x,int y) {
HDC wDC = GetDC(hWnd);
HDC bdc = CreateCompatibleDC(wDC);
// select the bitmap into the bitmap's dc
HBITMAP bOld = (HBITMAP)SelectObject(bdc,hbmImage);
// write into the window's dc
BitBlt(wDC,x,y,30,30,bdc,0,0,SRCCOPY);
// select the bitmap out of the bitmap dc
// so you can destroy the bitmap dc
SelectObject(bdc, bOld);
DeleteDC(bdc);
ReleaseDC(wDC);
}
void FillBitmapWithRed(void) {
HDC wDC = GetDC(hWnd);
HDC bDC = CreateCompatibleDC(wDC);
HBITMAP bOld = (HBITMAP)SelectObject(bDc,hbmImage);
HBRUSH brush = CreateSolidBrush(RGB(255,0,0));
RECT r = { 0,0,30,30 };
FillRect(bDC,&r,brush);
DeleteObject(brush);
SelectObject(bDC, bOld);
DeleteDC(bDC);
ReleaseDC(wDC);
}
void DestroyBitmap(void) {
DeleteObject(hbmImage);
}
I don't know what happens if you don't release/destroy/delete everything when you're done with it, but according to documentation it's a good idea.