16,472
社区成员
发帖
与我相关
我的任务
分享
CDC dc;
CDC* pDrawDC = pDC;
CBitmap bitmap;
CBitmap* pOldBitmap;
// only paint the rect that needs repainting
CRect client;
pDC->GetClipBox(client);
CRect rect = client;
pDC->LPtoDP(&rect);
rect.NormalizeRect();
if (!pDC->IsPrinting())
{
// draw to offscreen bitmap for fast looking repaints
if (dc.CreateCompatibleDC(pDC))
{
if (bitmap.CreateCompatibleBitmap(pDC, rect.Width(), rect.Height()))
{
OnPrepareDC(&dc, NULL);
pDrawDC = &dc;
// offset origin more because bitmap is just piece of the whole drawing
dc.OffsetViewportOrg(-rect.left, -rect.top);
pOldBitmap = dc.SelectObject(&bitmap);
dc.SetBrushOrg(rect.left % 8, rect.top % 8);
// might as well clip to the same rectangle
dc.IntersectClipRect(client);
}
}
}
// paint background
CBrush brush;
if (!brush.CreateSolidBrush(RGB(192,192,192)))
return;
brush.UnrealizeObject();
pDrawDC->FillRect(client, &brush);
pDrawDC->MoveTo(0,0);
pDrawDC->LineTo(100,100);
if (pDrawDC != pDC)
{
pDC->SetViewportOrg(0, 0);
pDC->SetWindowOrg(0,0);
pDC->SetMapMode(MM_TEXT);
dc.SetViewportOrg(0, 0);
dc.SetWindowOrg(0,0);
dc.SetMapMode(MM_TEXT);
pDC->BitBlt(rect.left, rect.top, rect.Width(), rect.Height(),
&dc, 0, 0, SRCCOPY);
dc.SelectObject(pOldBitmap);
}
int xLogPixPerInch = pDC->GetDeviceCaps(LOGPIXELSX);
int yLogPixPerInch = pDC->GetDeviceCaps(LOGPIXELSY);
pDC->SetMapMode(MM_ANISOTROPIC);
double dbX = 254;
double dbY = 254;
double tempX = dbX*dbZoom;
double tempY = dbY*dbZoom;
pDC->SetWindowExt(tempX,tempY);
pDC->SetViewportExt(xLogPixPerInch,yLogPixPerInch);