The
CMetaFileDC class represents metafile device contexts.
Metafile device contexts provide a means to draw into
Windows metafiles or the new enhanced
metafiles.
Metafile
device contexts differ from other device contexts in a
variety of ways. Most importantly, the m_hAttribDC member
of a metafile device context, which would normally be set
to refer to the same device as m_hDC, is set to NULL
instead. Thus, calls that would retrieve information about
the device context would typically fail for an object of
type CMetaFileDC.
It is
possible to assign a value to the m_hAttribDC member. For
example, you can assign it the value of another device
context that you created, which represents the screen, the
printer, or another output device.
Constructing
a metafile device context is a two-step process. First,
the CMetaFileDC object is created; next, its Create or
CreateEnhanced member functions are called.
Depending on
whether you supply a filename to the Create or
CreateEnhanced member functions or not, the metafile will
be either file-based or memory-based. A memory-based
metafile exists only temporarily.
When you are
finished with drawing into the metafile, you close the
metafile object by calling CMetaFileDC::Close or
CMetaFileDC::CloseEnhanced (depending on the type of the
metafile). These functions return a handle to a metafile
object. This handle can be used, for example, in a call to
CDC::PlayMetafile to play back the metafile into another
device context. It can also be passed to the Windows
function ::CopyMetaFile (or ::CopyEnhMetaFile) to copy the
metafile to a disk file.
As soon as
you call its Close or CloseEnhanced member function, you
can delete the CMetaFileDC object. When you are done with
using the metafile handle obtained through calling Close
or CloseEnhanced, you should delete the Windows metafile
object by calling DeleteMetaFile or
DeleteEnhMetaFile.
Example