void Ctest_display_ddbView::OnDraw(CDC* pDC)
{
Ctest_display_ddbDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)
return;
// TODO: 在此处为本机数据添加绘制代码
CBitmap Bitmap;
/*
* 如果要创建彩色位图,要用CreateCompatibleBitmap而不是CreateBitmap!!!
*/
//Bitmap.CreateBitmap(50,50,1,24,NULL);
Bitmap.CreateCompatibleBitmap(pDC,500,500);
BITMAP bm;
Bitmap.GetObject(sizeof(BITMAP),&bm);
unsigned char *pData =
new unsigned char [bm.bmHeight * bm.bmWidthBytes];
/*WORD BitsPerPixel = bm.bmBitsPixel;
CString strTmp;
strTmp.Format(_T("%d"), BitsPerPixel);
AfxMessageBox(strTmp);*/
for(int y = 0; y < bm.bmHeight; ++y)
{
for(int x = 0; x < bm.bmWidth; ++x)
{
pData[x * 4 + y * bm.bmWidthBytes] = 0;
pData[x * 4 + y * bm.bmWidthBytes + 1] = 0;
pData[x * 4 + y * bm.bmWidthBytes + 2] = 0;
pData[x * 4 + y * bm.bmWidthBytes + 3] = 0;
}
}
Bitmap.SetBitmapBits(bm.bmHeight * bm.bmWidthBytes, pData);
//delete pData;
CDC MemDC;
MemDC.CreateCompatibleDC(pDC);
CBitmap *pOldBitmap = MemDC.SelectObject(&Bitmap);
int nReturned = pDC->BitBlt(10, 10, bm.bmWidth, bm.bmHeight, &MemDC, 0, 0, SRCCOPY);
//pDC->StretchBlt(0,0, bm.bmWidth, bm.bmHeight, &MemDC,0,0,bm.bmWidth,bm.bmHeight,SRCCOPY);
MemDC.SelectObject(pOldBitmap);
delete pData;
UpdateData(false);
}