Delen via


CMetaFileDC Class

Implements a Windows metafile, which contains a sequence of graphics device interface (GDI) commands that you can replay to create a desired image or text.

class CMetaFileDC : public CDC

Members

Public Constructors

Name

Description

CMetaFileDC::CMetaFileDC

Constructs a CMetaFileDC object.

Public Methods

Name

Description

CMetaFileDC::Close

Closes the device context and creates a metafile handle.

CMetaFileDC::CloseEnhanced

Closes an enhanced-metafile device context and creates an enhanced-metafile handle.

CMetaFileDC::Create

Creates the Windows metafile device context and attaches it to the CMetaFileDC object.

CMetaFileDC::CreateEnhanced

Creates a metafile device context for an enhanced-format metafile.

Remarks

To implement a Windows metafile, first create a CMetaFileDC object. Invoke the CMetaFileDC constructor, then call the Create member function, which creates a Windows metafile device context and attaches it to the CMetaFileDC object.

Next send the CMetaFileDC object the sequence of CDC GDI commands that you intend for it to replay. Only those GDI commands that create output, such as MoveTo and LineTo, can be used.

After you have sent the desired commands to the metafile, call the Close member function, which closes the metafile device contexts and returns a metafile handle. Then dispose of the CMetaFileDC object.

CDC::PlayMetaFile can then use the metafile handle to play the metafile repeatedly. The metafile can also be manipulated by Windows functions such as CopyMetaFile, which copies a metafile to disk.

When the metafile is no longer needed, delete it from memory with the DeleteMetaFile Windows function.

You can also implement the CMetaFileDC object so that it can handle both output calls and attribute GDI calls such as GetTextExtent. Such a metafile is more flexible and can more easily reuse general GDI code, which often consists of a mix of output and attribute calls. The CMetaFileDC class inherits two device contexts, m_hDC and m_hAttribDC, from CDC. The m_hDC device context handles all CDC GDI output calls and the m_hAttribDC device context handles all CDC GDI attribute calls. Normally, these two device contexts refer to the same device. In the case of CMetaFileDC, the attribute DC is set to NULL by default.

Create a second device context that points to the screen, a printer, or device other than a metafile, then call the SetAttribDC member function to associate the new device context with m_hAttribDC. GDI calls for information will now be directed to the new m_hAttribDC. Output GDI calls will go to m_hDC, which represents the metafile.

For more information on CMetaFileDC, see Device Contexts.

Inheritance Hierarchy

CObject

CDC

CMetaFileDC

Requirements

Header: afxext.h

See Also

Reference

CDC Class

Hierarchy Chart