怎么在CScrollView中实现MM_ISOTROPIC模式下图形(绘图)的滚动
如何在CScrollView中实现MM_ISOTROPIC模式下图形(绘图)的滚动
之前在贴上看到过以下的处理方式 但是我试了 不好使 有高手实现过的话请不吝指教,请将过程说清楚 godstoneid@yahoo.com.cn(我的邮箱)
从CScroolView类继承,
在OnPrepareDC中这样写:
pDC-> SetMapMode(MM_ISOTROPIC);
pDC-> SetWindowOrg((int)(-m_fXOrg*1000),(int)(m_fYOrg*1000));
pDC-> SetWindowExt(1000,-1000);
pDC-> SetViewportExt(1,1);
------解决方案--------------------
void CXXXView::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo)
{
CScrollView::OnPrepareDC(pDC, pInfo);
// mapping mode is MM_ANISOTROPIC
// these extents setup a mode similar to MM_LOENGLISH
// MM_LOENGLISH is in .01 physical inches
// these extents provide .01 logical inches
pDC-> SetMapMode(MM_ANISOTROPIC);
pDC-> SetWindowExt(100, -100);
pDC-> SetViewportExt(pDC-> GetDeviceCaps(LOGPIXELSX),pDC-> GetDeviceCaps(LOGPIXELSY));
// set the origin of the coordinate system to the center of the page
CPoint ptOrg;
ptOrg.x = GetDocument()-> GetSize().cx / 2;
ptOrg.y = GetDocument()-> GetSize().cy / 2;
// ptOrg is in logical coordinates
pDC-> OffsetWindowOrg(-ptOrg.x,ptOrg.y);
}
void CXXXView::OnDraw(CDC* pDC)
{
CDrawEleDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
CDC dc;
CDC* pDrawDC = pDC;
CBitmap bitmap;
CBitmap* pOldBitmap = 0;
// only paint the rect that needs repainting
CRect client;
pDC-> GetClipBox(client);
CRect rect = client;
DocToClient(rect);
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(pDoc-> GetPaperColor()))
return;
brush.UnrealizeObject();
pDrawDC-> FillRect(client, &brush);
////////////////////////
CBrush brush1;
if (!brush1.CreateSolidBrush(pDoc-> GetPaperColor()))
return;
CRect rect1;
rect1.left = -pDoc-> GetSize().cx / 2;
rect1.top = -pDoc-> GetSize().cy / 2;
rect1.right = rect1.left + pDoc-> GetSize().cx;
rect1.bottom = rect1.top + pDoc-> GetSize().cy;
brush1.UnrealizeObject();
pDrawDC-> FillRect(rect1, &brush1);
////////////////////////绘制你真正要绘制的内容
pDoc-> Draw(pDrawDC, this);
///end
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);
}
}
之前在贴上看到过以下的处理方式 但是我试了 不好使 有高手实现过的话请不吝指教,请将过程说清楚 godstoneid@yahoo.com.cn(我的邮箱)
从CScroolView类继承,
在OnPrepareDC中这样写:
pDC-> SetMapMode(MM_ISOTROPIC);
pDC-> SetWindowOrg((int)(-m_fXOrg*1000),(int)(m_fYOrg*1000));
pDC-> SetWindowExt(1000,-1000);
pDC-> SetViewportExt(1,1);
------解决方案--------------------
void CXXXView::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo)
{
CScrollView::OnPrepareDC(pDC, pInfo);
// mapping mode is MM_ANISOTROPIC
// these extents setup a mode similar to MM_LOENGLISH
// MM_LOENGLISH is in .01 physical inches
// these extents provide .01 logical inches
pDC-> SetMapMode(MM_ANISOTROPIC);
pDC-> SetWindowExt(100, -100);
pDC-> SetViewportExt(pDC-> GetDeviceCaps(LOGPIXELSX),pDC-> GetDeviceCaps(LOGPIXELSY));
// set the origin of the coordinate system to the center of the page
CPoint ptOrg;
ptOrg.x = GetDocument()-> GetSize().cx / 2;
ptOrg.y = GetDocument()-> GetSize().cy / 2;
// ptOrg is in logical coordinates
pDC-> OffsetWindowOrg(-ptOrg.x,ptOrg.y);
}
void CXXXView::OnDraw(CDC* pDC)
{
CDrawEleDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
CDC dc;
CDC* pDrawDC = pDC;
CBitmap bitmap;
CBitmap* pOldBitmap = 0;
// only paint the rect that needs repainting
CRect client;
pDC-> GetClipBox(client);
CRect rect = client;
DocToClient(rect);
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(pDoc-> GetPaperColor()))
return;
brush.UnrealizeObject();
pDrawDC-> FillRect(client, &brush);
////////////////////////
CBrush brush1;
if (!brush1.CreateSolidBrush(pDoc-> GetPaperColor()))
return;
CRect rect1;
rect1.left = -pDoc-> GetSize().cx / 2;
rect1.top = -pDoc-> GetSize().cy / 2;
rect1.right = rect1.left + pDoc-> GetSize().cx;
rect1.bottom = rect1.top + pDoc-> GetSize().cy;
brush1.UnrealizeObject();
pDrawDC-> FillRect(rect1, &brush1);
////////////////////////绘制你真正要绘制的内容
pDoc-> Draw(pDrawDC, this);
///end
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);
}
}