兼容的DC指不是具体的图形设备,而是虚拟的设备,例如我们可以建一个虚拟的DC来存放和画bitmap,兼容DC的类 可以理解成CDC的派生类,可以调用CDC的各种绘图函数。
void CMDI_testView::OnDraw(CDC* pDC)
{
CMDI_testDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
CDC pMemClientDC;
CRect m_rcClient;
//得到客户区域的填充矩形
GetClientRect(&m_rcClient);
pMemClientDC.CreateCompatibleDC(pDC);
CBitmap bmp;
bmp.CreateCompatibleBitmap(pDC,m_rcClient.Width(),m_rcClient.Height());
pMemClientDC.SelectObject(&bmp);
int nWidth = m_rcClient.Width();
int nHeight = m_rcClient.Height();
CRect rectangle;
pMemClientDC.FillSolidRect(&m_rcClient,RGB(0,255,255));
//分割客户区域成小矩形,逐个填充
for(int i = 0;i < nWidth;i++ )
{
rectangle.SetRect(i, 0, i+1, nHeight);
pMemClientDC.FillSolidRect(&rectangle, RGB(ColorR, ColorG, 255-MulDiv(i, 255, nWidth)));
}
pDC->BitBlt(0,0,nWidth,nHeight,&pMemClientDC,0,0,SRCCOPY);
pMemClientDC.DeleteDC();
}