A metafile is a graphics object that stores graphics commands. Functions that draw to a device context or set attributes of a device context have a corresponding metafile record.

Creating and Using Metafiles

To create a metafile, a metafile device context may be opened via the function CreateMetafile. Win+ deals only with enhanced metafiles. A simple example of using metafiles has been included and its output is shown below.

Below is shown another snapshot where several different instances of the same program are running.

It should be clear that the original picture was square; however, when displayed, the aspect ratio was not preserved.

Saving a Metafile to Disk

The program of this section is similar to that of the last in that it creates a metafile; however, it saves the metafile to disk and later reloads it when painting the client window. See the source code listing file.

The output of the program is identical to the output of the previous program. Note that loading a metafile each time the window is painted is not efficient. The actual size that the metafile is intended to be played is stored in the header and may be ascertained via the function GetMetafileHeader.