A Windows application must create a metafile in a special device context. It cannot use the device contexts that the CreateDC or GetDC functions return; instead, it must use the device context that the CreateMetaFile function returns.
Windows allows an application to use a subset of the GDI functions to create a metafile. This subset is the set of all GDI functions that create output (it is not necessary to use those functions that provide state information, such as the GetDeviceCaps or GetEnvironment functions). The following is a list of GDI functions an application can use in a metafile:
To create output with a metafile, an application must follow four steps:
1.Create a special device context by using the CreateMetaFile function.
2.Send GDI commands to the metafile by using the special device context.
3.Close the metafile by calling the CloseMetaFile function. This function returns a metafile handle.
4.Display the image or text on a device by using the PlayMetaFile function, passing to the function the metafile handle obtained from CloseMetaFile and a device-context handle for the device to which the metafile is to be played.
The device context which CreateMetaFile creates does not have default attributes of its own. Whatever device-context attributes are in effect for the output device when an application plays a metafile will be the defaults for the metafile. The metafile can change these attributes while it is playing. If the application needs to retain the same device-context attributes after the metafile has finished playing, it should save the output device context by calling the SaveDC function before calling PlayMetaFile. Then, when PlayMetaFile returns, the application can call the RestoreDC function (with –1 as the nSavedDC parameter) to restore the original device-context attributes.
Although the maximum size of a metafile is 232 bytes or records, the actual size of a metafile is limited by the amount of memory or disk space available.