The information in this article applies to:
SYMPTOMSWhen displaying a metafile within the Microsoft Foundation Classes (MFC) Print and Print Preview architecture, the metafile prints correctly but is only partially or incorrectly displayed in the Print Preview window. CAUSE
To simulate a printed page in a window, CPreviewDC modifies the mapping
mode for the Print Preview window by changing the parameters for such calls
as SetWindowExt() and SetMapMode() before passing them
on to the attribute and output device contexts (DCs). RESOLUTIONRather than PlayMetaFile(), use SaveDC(), ::EnumMetaFile(), and RestoreDC() to play the metafile. In the metafile enumeration callback procedure, trap the following functions and call the equivalent CDC functions:
(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.)Bracket the call to ::EnumMetaFile() between calls to SaveDC() and RestoreDC() to ensure that the output and attribute DCs are correctly synchronized after playing the metafile. MORE INFORMATIONThe enumeration callback procedure should handle the above functions by calling the (virtual) CDC version of the function while passing everything else to PlayMetaFileRecord(). This allows CPreviewDC to keep the output DC and the attribute DC correctly synchronized with respect to mapping mode. For example: Sample Code
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.Also, it is common for applications to set a different mapping mode before playing a metafile (depending on the metafile) and this mapping mode may conflict with the mapping mode used by the rest of the view class. For these reasons, if any drawing will take place after playing the metafile (including playing another metafile, or even the same metafile again), the DC must be restored to the state it was in prior to playing the metafile. This can be accomplished by using SaveDC/RestoreDC, as in the following example:
Additional query words:
Keywords : kbprint kbMapMode kbMetafile kbMFC kbPrinting kbVC kbDSupport kbGrpMFCATL |
Last Reviewed: November 25, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |