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;
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;