1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
|
// Need to call DeleteObject on returned bitmap handle when
// done with it
HBITMAP
CreateSolidBitmap(HDC hdc, int width, int height, COLORREF cref)
{
// Create compatible memory DC and bitmap, and a solid brush
HDC hdcMem = CreateCompatibleDC(hdc);
HBITMAP hbmp = CreateCompatibleBitmap(hdcMem, width, height);
HBRUSH hbrushFill = CreateSolidBrush(cref);
// Select the bitmap and brush into DC
HBITMAP hbmpOld = (HBITMAP)SelectObject(hdcMem, hbmp);
HBRUSH hbrushOld = (HBRUSH)SelectObject(hdcMem, hbrushFill);
// Fill the whole area with solid color
Rectangle(hdcMem, 0, 0, width, height);
// Restore old bitmap and brush
SelectObject(hdcMem, hbmpOld);
SelectObject(hdcMem, hbrushOld);
// Delete brush
DeleteObject(hbrushFill);
// Delete memory DC
DeleteDC(hdcMem);
// Set preferred dimensions
SetBitmapDimensionEx(hbmp, width, height, NULL);
return hbmp;
}
|