Chapter 74 Metafiles

74.1 About Metafiles

A metafile is one of two graphic tools that is used to store pictures created by your Win32 application (the other tools is the bitmap). Unlike a bitmap, a metafile guarantees device-independence. This means that when your application creates a picture measuring 2 inches by 4 inches on a VGA display and stores that picture in a metafile, it (the picture) will maintain those original dimensions when it is printed on a 300 dpi laser printer or copied over a network and displayed in another application that is running on an 8514/A video display. This device independence is the one feature that sets metafiles apart from bitmaps. There is a cost however— metafiles are generally drawn slower than bitmaps. Therefore, if your application requires fast drawing (and device independence is not an issue) you should use bitmaps instead of metafiles.

Internally, a metafile is an array of variable length data structures called records. The first records in the metafile specify general information such as the resolution of the device upon which the picture first appeared, the dimensions of the picture, and so on. The remaining records (which constitute the bulk of any metafile) correspond to the GDI function calls which were required to draw the picture. These records are stored in the metafile after you create a special metafile device-context and use this DC for all drawing operations required to create the picture. When Windows processes a GDI function associated with a metafile DC, it converts the function call into the appropriate data and stores this data in a record which is appended to the metafile.

Once a picture is complete and the last record has been stored in the metafile, the metafile can be passed (via the clipboard) to another application, embedded within another file, stored on disk, or played repeatedly. (A metafile is played when its records are converted to device commands and processed by the appropriate device.)

There are two types of metafiles: enhanced and windows. Enhanced metafiles are compatible with Win32 while windows metafiles are compatible with Windows version 3.x. Windows metafiles are limited in their capabilities and should rarely be used—the windows metafile API are supported in order to maintain backwards compatibility with applications that were written for Windows version 3.x. Enhanced metafiles (as the name implies) are an improvement over the original metafile format. Enhanced metafiles provide true device independence. You can think of the picture stored in an enhanced metafile as a “snapshot” of the video display which is taken at a particular point in time. This “snapshot” maintains its dimensions no matter where it appears: whether it's on a printer, on a plotter, on the desktop, or in the client-area of any Win32 application.