Knowledge Base Nr: 00298 scrollzoom.cpp - http://www.swe-kaiser.de

Downloads:

MFC: VS2005 Scaling in ScrollView mit mapping mode != MM_xxxISOTROPIC (z.b. MM_LOMETRIC, MM_HIMETRIC, ...)

  
- in h-file von view definieren
float fScale;
float fOldScale;
float Scale(float v) { return fScale*v; }

- initialisieren in OnInitialUpdate() oder Konstruktor
fScale = 1.2;

- messagehandler für zoom-faktor

void ClulliView::OnZoomZoomin()
{
fScale += 0.2;
if (fScale > 3.0)
fScale = 3.0;
Invalidate();
UpdateWindow();
RedrawWindow();
}

void ClulliView::OnZoomZoomout()
{
fScale -= 0.2;
if (fScale < 0.2)
fScale = 0.2;
Invalidate();
UpdateWindow();
RedrawWindow();
}

- drucken korrigieren (ohne zoom)
void ClulliView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
fOldScale = fScale;
fScale = 1;
}

void ClulliView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
fScale = fOldScale;
}

- scalierung beim zeichnen berücksichtigen
void ClulliView::OnDraw(CDC* pDC)
{
...
//font
CFont cfNew;
LOGFONT lf;
CFont* cfOld;

memset(&lf, 0, sizeof(LOGFONT));
lf.lfHeight = Scale(30);
wcscpy(lf.lfFaceName, CString("Arial"));
cfNew.CreateFontIndirect(&lf);

cfOld = pDC->SelectObject(&cfNew);

//seitengröße beim zoomen anpassen
CSize sizeTotal;
sizeTotal.cx = Scale(2100);
sizeTotal.cy = Scale(2900);
SetScrollSizes(MM_LOMETRIC, sizeTotal); //nicht möglich mit MM_ISOTROPIC!!!

CString str;

int x = -200;
int y = -200;
str.Format(CString("Zoom: %.2f - SetWindowOrg(%d/%d)"), fScale, x, y);
pDC->TextOut(Scale(500), Scale(-2800),str, str.GetLength());

//pDC->ScaleWindowExt(xNum, xDenom, yNum, yDenom); //keine auswirkung mapping mode MM_LOMETRIC!!!

//SetWindowExtEx() nicht mapping mode MM_LOMETRIC!!!
pDC->SetWindowOrg(Scale(x), Scale(y));

for (int i=0; i<30; i++)
{
x = Scale(i*50);
y = Scale(-2900 + i*50);
str.Format(CString("%d/%d lulli lulli"), x, y);
pDC->TextOut(x, y,str, str.GetLength());

pDC->MoveTo(0, 0);
pDC->LineTo(x, 0);
pDC->LineTo(x, y);
pDC->LineTo(0, y);
pDC->LineTo(0, 0);
}

pDC->SelectObject(cfOld);
cfNew.DeleteObject();
}