双缓冲绘图:当内存DC的映射模式设为非MM_TEXT后,显示DC的属性和BitBlt函数参数应该作哪些相应的改动?

chencb 2009-12-10 02:15:43
这里我是指在调用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的坐标。
...全文
179 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

7,540

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 VC.NET
社区管理员
  • VC.NET社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧