Article ID: 105443
Article Last Modified on 11/21/2006
SetMapMode SetWindowExt, ScaleWindowExt SetViewportExt, ScaleViewportExt SetViewportOrg, OffsetViewportOrg(Of these, SetWindowExt occurs in metafiles more often than the rest. It is generally not recommended that metafiles contain records for SetMapMode or any of the Viewport functions, but it is common to find SetMapMode records in metafiles anyway.)
int CALLBACK __export EnumMFProc(HDC hdc,
HANDLETABLE FAR *lpht,
METARECORD FAR *lpmr,
int cObj,
LPARAM lParam)
{
// lParam is available for passing application-specific data to the
// enum proc (via the last parameter to EnumMetaFile). Let's make
// things easier by passing in a pointer to the CDC object.
CDC *pDC = (CDC *)lParam;
switch(lpmr->rdFunction)
{
// SetWindowExt and SetMapMode are the most important ones to
// look for.
case META_SETWINDOWEXT:
pDC->SetWindowExt(lpmr->rdParm[1], lpmr->rdParm[0]);
break;
case META_SETMAPMODE:
pDC->SetMapMode(lpmr->rdParm[0]);
break;
case META_SETVIEWPORTEXT:
pDC->SetViewportExt(lpmr->rdParm[1], lpmr->rdParm[0]);
break;
case META_SETVIEWPORTORG:
pDC->SetViewportOrg(lpmr->rdParm[1], lpmr->rdParm[0]);
break;
// Add cases for the others if desired...
default:
PlayMetaFileRecord(hdc, lpht, lpmr, cObj);
}
return 1;
}
In addition to the functions listed above, there are other functions that
will not affect the appearance of the metafile in the Print Preview window,
but may affect the synchronization of the output and attribute DCs used by
CPreviewDC. This can affect subsequent drawing. Consider that the metafile
may select different fonts and other objects into the output DC, may change
the foreground/background colors, the text alignment flags, and so forth.
pDC->SaveDC(); // Save current state of DC
pDC->SetMapMode(MM_ANISOTROPIC); // Scalable metafile
pDC->SetViewportExt(xExt, yExt); // Size of picture
pDC->SetViewportOrg(x, y); // Location of picture
::EnumMetaFile(pDC->GetSafeHdc(), hmf, EnumMFProc, (LPARAM)(LPSTR)pDC);
pDC->RestoreDC(-1); // Restore to previous saved state
// Continue with other drawing...
Keywords: kbmetafile kbprint kbprb KB105443