When a metafile device context is associated with a presentation space, presentation space resources (such as the current logical color table) and environmental settings (such as the presentation-page format) are copied automatically into the metafile. These items must be established before the presentation space is associated with the metafile device context.
Loading of additional resources (such as fonts) and adjustments to the environment (such as modifying the default viewing transform) should be made before you begin drawing. Attribute settings, segment-creation requests, and primitive-drawing requests that contribute to the picture are directed to the metafile after its device context has been associated with a presentation space.
If an application calls GpiSetDrawControl, specifying DCTL_DISPLAY and DCTL_OFF, before drawing graphics into a metafile, the graphics are not visible when the metafile is played. However, the metafile records any changes made to the current position or presentation-space attributes.
When the metafile device context has been associated with a graphics presentation space, the metafile is ready to receive graphical data. Just as with any other output destination, whether the picture is sent directly to the metafile is controlled by the current drawing mode, as shown in the following table.
Drawing Mode Dependencies When Recording Metafiles
┌──────────────────────┬──────────────────────────────────────┐ │Drawing Mode │Effect │ ├──────────────────────┼──────────────────────────────────────┤ │Draw mode │Graphics go directly to the metafile. │ ├──────────────────────┼──────────────────────────────────────┤ │Retain mode │Graphics go to the segment store of │ │ │the presentation space. They are not │ │ │directed to the metafile until the │ │ │application issues an appropriate │ │ │GpiDraw... request (GpiDrawChain, │ │ │GpiDrawFrom, GpiDrawSegment). │ ├──────────────────────┼──────────────────────────────────────┤ │Draw-and-retain mode │Graphics go directly to the metafile, │ │ │and also to the segment store of the │ │ │presentation space. │ └──────────────────────┴──────────────────────────────────────┘
The drawing mode can be changed at any time while the metafile device context remains open by calling GpiSetDrawingMode.
As long as the metafile device context remains open, you can continue drawing. A metafile can only contain data generated from GPI functions. Any nongraphical data included in a metafile is ignored. The following list describes items found in a metafile:
When an application finishes drawing in a metafile, it must disassociate the metafile device context from the presentation space by calling GpiAssociate. If the metafile is associated with or through a micro presentation space, call GpiDestroyPS to perform an implicit disassociation.
When you have finished drawing in the metafile, and the presentation space has been disassociated, the application can close the metafile device context and obtain a handle to the metafile by calling DevCloseDC. A closed metafile cannot be reopened; therefore, additional drawing in the metafile is not possible. A closed metafile can be referenced by the metafile handle. The metafile handle is used to reference the metafile for subsequent operations on the metafile. Use the metafile handle to:
Because each metafile can be distinctly identified, your application can work with more than one metafile at a time. However, because metafiles can be very large files, you must make maximum use of the metafile handles to avoid duplicating the actual metafiles in memory.