   Bitblt-ing a background color...
  I have implemented a tear-free bitblt operation using double buffering.  However, my background color controls aren't working.  I have attempted to change the background color during the pre-bitblt buffer as I have seen others implement it.  However, FillRect() isn't working.  It isn't updating the background at all.  Can someone take a look at my code and tell me why this isn't working properly?  Thanks!case WM_PAINT:BITMAP bm;    //Bitmap object for drawingHBITMAP bitmap;hdc= BeginPaint(hWnd, &psDraw);   //Get the window device contexthdcBufferOne = CreateCompatibleDC(hdc);//Create a memory device context compatible with the windowhdcMem  = CreateCompatibleDC(hdc);//Create a memory device context compatible with the windowbitmap  = CreateCompatibleBitmap(hdc,Image.GetImageWidth(),Image.GetImageHeight());hOld    = SelectObject(hdcBufferOne, bitmap);   //Move the mask to the memory device context and store the information from hdcMemFillRect(hdcBufferOne, &rcWholeScreen, CreateSolidBrush(RGB(fScrollPosition[SCROLLRED], fScrollPosition[SCROLLGREEN], fScrollPosition[SCROLLBLUE])));GetObject(Image.GetBitmapHandle(), sizeof(bm), &bm);   //Move the stored image to the bitmap objectBitBlt(hdcMem, STARTOFDRAWINGFIELD, TOOLBAROFFSET, bm.bmWidth, bm.bmHeight, hdcBufferOne, iHorizontalScroll, iVerticalScroll, SRCAND);   //Copy the memory device context (mask) to the windowSelectObject(hdcBufferOne, Image.GetBitmapHandle());   //Move the image to the memory device contextBitBlt(hdcMem, STARTOFDRAWINGFIELD, TOOLBAROFFSET, bm.bmWidth, bm.bmHeight, hdcBufferOne, iHorizontalScroll, iVerticalScroll, SRCPAINT);   //Copy the memory device context (image) to the window for the whole imageBitBlt(hdc, STARTOFDRAWINGFIELD, TOOLBAROFFSET, bm.bmWidth, bm.bmHeight, hdcBufferOne, iHorizontalScroll, iVerticalScroll, SRCCOPY);   //Copy the memory device context (image) to the window for the whole imageSelectObject(hdcBufferOne, hOld);   //Move the mask to the memory device contextDeleteDC(hdcBufferOne);   //Delete the memory device contextDeleteDC(hdcMem);   //Delete the memory device contextEndPaint(hWnd, &psDraw); //Mark the end of paintingbreak;
  Is FillRect() or CreateBrush() failing? You are leaking an HBRUSH by not storing and then deleting the brush created with CreateBrush() as well.   ;  I added checks to both of the return values.  They both test properly.HBRUSH test = CreateSolidBrush(RGB(fScrollPosition[SCROLLRED], fScrollPosition[SCROLLGREEN], fScrollPosition[SCROLLBLUE]));if(!test){MessageBox(NULL, "Oh snap!", "The program has encountered a problem", MB_ICONERROR );}int test2 = FillRect(hdcBufferOne, &rcWholeScreen, test);if(!test2){MessageBox(NULL, "Oh snap again!", "The program has encountered a problem", MB_ICONERROR );};  Bump.   ;  Doesn't the last BitBlt uses the wrong source DC? Seems like it should be hdcMem rather than hdcBufferOne, because that just straight copies the image. You'll definitely also need to select something into hdcMem before the first BltBlt or it's contents will stay all black. The 'bitmap' variable is also leaked.   ;  A little off topic - that's horribly inefficient; you shouldn't be creating and destroying two device contexts, a bitmap and a brush for every WM_PAINT, you should create them at startup and destroy them at cleanup.You're also not storing and restoring the handle returned by SelectObject(), which is another resource leak.As for the actual problem, you seem to be writing into hdcMem in the first two BitBlt calls, but you don't use that result, and just delete the DC. The only writes to the DC shown on the window is in the last BitBlt line; a straight copy from hdcBufferOne.   