Instead of drawing using Moveto
and LineTo
, I want to use a hand made bitmap, that I will fill with an array that I will create myself, and use that to fill the screen.
Right now, the array is just filled with red, But when I draw to the screen I get all black.
This is the code:
void CCGWorkView::OnDraw(CDC* pDC)
{
CCGWorkDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)
return;
pDCToUse->FillSolidRect(&r, world.bg_color);
BITMAPINFO bminfo;
CPaintDC hdc(this);
CRect rect;
GetWindowRect(&rect);
int h = rect.bottom - rect.top,
w = rect.right - rect.left;
int *bits = new int[w * h];
HDC hdcMem = CreateCompatibleDC(hdc);
HBITMAP bm = CreateCompatibleBitmap(hdc, w, h);
SelectObject(hdcMem, bm);
bminfo.bmiHeader.biSize = sizeof(bminfo.bmiHeader);
bminfo.bmiHeader.biWidth = w;
bminfo.bmiHeader.biHeight = h;
bminfo.bmiHeader.biPlanes = 1;
bminfo.bmiHeader.biBitCount = 32;
bminfo.bmiHeader.biCompression = BI_RGB;
bminfo.bmiHeader.biSizeImage = 0;
bminfo.bmiHeader.biXPelsPerMeter = 1;
bminfo.bmiHeader.biYPelsPerMeter = 1;
bminfo.bmiHeader.biClrUsed = 0;
bminfo.bmiHeader.biClrImportant = 0;
for (int i = 0; i < w * h; i++) {
bits[i] = RGB(255, 0, 0);
}
SetDIBits(hdcMem, bm, 0, h, bits, &bminfo, 0);
BitBlt(hdc, rect.left, rect.top, w, h, hdcMem, rect.left, rect.top, SRCCOPY);
DeleteDC(hdcMem);
DeleteObject(bm);
delete bits;
}