Click to See Complete Forum and Search --> : Bitblt-ing a background color...


SirNoods
June 2nd, 2009, 07:43 PM
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 to suggest why my program may not be working? Thanks!

case WM_PAINT:
BITMAP bm; //Bitmap object for drawing
HBITMAP bitmap;
hdc = BeginPaint(hWnd, &psDraw); //Get the window device context
hdcBufferOne = CreateCompatibleDC(hdc); //Create a memory device context compatible with the window
hdcMem = CreateCompatibleDC(hdc); //Create a memory device context compatible with the window
bitmap = CreateCompatibleBitmap(hdc,Image.GetImageWidth(),Image.GetImageHeight());
hOld = SelectObject(hdcBufferOne, bitmap); //Move the mask to the memory device context and store the information from hdcMem

FillRect(hdcBufferOne, &rcWholeScreen, CreateSolidBrush(RGB(fScrollPosition[SCROLLRED], fScrollPosition[SCROLLGREEN], fScrollPosition[SCROLLBLUE])));
GetObject(Image.GetBitmapHandle(), sizeof(bm), &bm); //Move the stored image to the bitmap object
BitBlt(hdcMem, STARTOFDRAWINGFIELD, TOOLBAROFFSET, bm.bmWidth, bm.bmHeight, hdcBufferOne, iHorizontalScroll, iVerticalScroll, SRCAND); //Copy the memory device context (mask) to the window

SelectObject(hdcBufferOne, Image.GetBitmapHandle()); //Move the image to the memory device context
BitBlt(hdcMem, STARTOFDRAWINGFIELD, TOOLBAROFFSET, bm.bmWidth, bm.bmHeight, hdcBufferOne, iHorizontalScroll, iVerticalScroll, SRCPAINT); //Copy the memory device context (image) to the window for the whole image
BitBlt(hdc, STARTOFDRAWINGFIELD, TOOLBAROFFSET, bm.bmWidth, bm.bmHeight, hdcBufferOne, iHorizontalScroll, iVerticalScroll, SRCCOPY); //Copy the memory device context (image) to the window for the whole image

SelectObject(hdcBufferOne, hOld); //Move the mask to the memory device context
DeleteDC(hdcBufferOne); //Delete the memory device context
DeleteDC(hdcMem); //Delete the memory device context
EndPaint(hWnd, &psDraw); //Mark the end of painting
break;

srelu
June 3rd, 2009, 07:10 AM
Nobody can help you as long as you only post a portion of code stuffed with unknown variables.

Check the parameters of the FillRect function.
Make sure you have a valid brush.
Make sure you use client rect coordinates for your rectangle .
Check the rectangle coordinates and make sure it's normalized.
Be aware that the "right" and "bottom" members of the rectangle structure are not the same as the "width" and "height".

If you have background painting issues it's a good ideea to move the background painting code to WM_ERASEBKGND.

Marc G
June 4th, 2009, 04:37 AM
In addition to what srelu said, you have a resource leak. You are creating a brush using CreateSolidBrush and you should release that brush using DeleteObject.