双缓冲绘图:当内存DC的映射模式设为非MM_TEXT后,显示DC的属性和BitBlt函数参数应该作哪些相应的改动?
这里我是指在调用BitBlt之前不恢复内存DC的映射模式为MM_TEXT的情况下,如何正确的使用双缓冲绘图。关键问题在于BitBlt的两个起点参数的设置。
CRect rect;
GetClientRect(&rect);
int width = rect.Width();
int height = rect.Height();
pDC->SetMapMode(MM_ANISOTROPIC);
pDC->SetWindowExt(2, -2);
pDC->SetViewportExt(1, 1);
pDC->SetViewportOrg(width/2, height/2);
CDC memDC;
memDC.CreateCompatibleDC(pDC);
CBitmap memBitmap;
memBitmap.CreateCompatibleBitmap(pDC, width, height);
CBitmap * pOldBitmap = memDC.SelectObject(&memBitmap);
memDC.SetMapMode(MM_ANISOTROPIC);
memDC.SetWindowExt(2, 2);
memDC.SetViewportExt(1, -1);
memDC.SetViewportOrg(width/2, height/2);
memDC.SelectObject(GetStockObject(WHITE_BRUSH));
memDC.Rectangle(-width, height, width, -height);
memDC.MoveTo(-width, 0);
memDC.LineTo(width, 0);
memDC.MoveTo(0, height);
memDC.LineTo(0, -height);
srand(1);
for(int i=0; i < 20; i++)
{
int x = rand() % (2 * width) - width;
int y = rand() % (2 * height) - height;
CString string;
string.Format(_T("%d,%d"), x, y);
memDC.TextOut(x, y, string, string.GetLength());
}
pDC->BitBlt(-width, -height, 2*width, 2*height, &memDC, -width, -height, SRCCOPY);
memDC.SelectObject(pOldBitmap);
memBitmap.DeleteObject();
memDC.DeleteDC();
针对上面这段正确的代码,哪位高手给详细说说针对不同的映射模式,如何确定upper-left corner of the destination rectangle和upper-left corner of the source bitmap的坐标。