Windows Metafile Functions & Aldus Placeable Metafiles

Last reviewed: July 22, 1997
Article ID: Q66949
3.00 3.10 WINDOWS kbprg

The information in this article applies to:

  • Microsoft Windows Software Development Kit (SDK) for Windows versions 3.0 and 3.1

SUMMARY

Many Windows-based applications import or export Windows metafiles in a format known as the Aldus Placeable Metafile (APM) format. In this format, these metafiles cannot be used with the Windows metafile functions such as GetMetaFile(), CopyMetaFile(), PlayMetaFile(), etc. To use these metafiles, the APM header must be removed from the metafile and the remaining metafile bits must be written to a newly created metafile.

MORE INFORMATION

The APM header is 22 bytes in length and is defined as follows:

typedef struct

  {
  DWORD   key;
  HANDLE  hmf;
  RECT    bbox;
  WORD    inch;
  DWORD   reserved;
  WORD    checksum;
  } APMFILEHEADER;

The following code fragment demonstrates how to create a memory-based Windows metafile from an Aldus Placeable Metafile that will work with the metafile functions provided by Windows.

More information regarding the APM format is available from the Aldus FAX Info System via a fax machine telephone at (206) 628-5737. It will ask for the document number, which is 9108 for the APM format. It will then ask you to push start on your FAX machine.

The Placeable Windows Metafiles are also documented on pages 26-27 of the "Programmer's Reference, Volume 4: Resources" manual from the Windows 3.1 SDK documentation.

NOTE: This an open line and no registration fees are required.

The phone number for Aldus Technical Information is (206) 628-2040.

BOOL RenderAPM (fh)

int   fh; // a file handle to the APM metafile is passed in
{
    HANDLE           hData;
    LPSTR            lpData;
    DWORD            OffsetToMeta;
    METAHEADER       mfHeader;
    APMFILEHEADER    APMHeader;

    OffsetToMeta = sizeof(APMHeader);

// Seek to beginning of file and read APM header
    _llseek(fh, 0, 0);
    if (!_lread(fh, (LPSTR)&APMHeader, sizeof(APMFILEHEADER)))
        // Error in reading the file
        return(FALSE);

// Return to read metafile header
    _llseek(fh, OffsetToMeta, 0);
    if (!_lread(fh, (LPSTR)&mfHeader, sizeof(METAHEADER)))
        // Error in reading
        return(FALSE);

// Allocate memory for memory based metafile
    if (!(hData = GlobalAlloc(GHND, (mfHeader.mtSize * 2L))))
        return(FALSE);
// Were we successful?
    if (!(lpData = GlobalLock(hData)))
    {
        // Error in allocation
        GlobalFree(hData);
        return(FALSE);
    }

// Read metafile bits
    _llseek(fh, OffsetToMeta, 0);
    if (!_lread(fh, lpData, (mfHeader.mtSize * 2L)))
    {
        // Error in reading
        GlobalUnlock(hData);
        GlobalFree(hData);
        return(FALSE);
    }

// Create the METAFILE with the bits we read in.
    if (!(hMF = SetMetaFileBits(hData)))
        return(FALSE);

    GlobalUnlock(hData);

// Close the APM file
    _lclose(fh);

// Return success
    return(TRUE);
}


Additional reference words: 3.00 3.10 CloseMetaFile CopyMetaFile
CreateMetaFile EnumMetaFile GetMetaFile PlayMetaFile PlayMetaFileRecord
SetMetaFileBits SetMetaFileBitsBetter
KBCategory: kbprg
KBSubcategory: GdiMeta
Keywords : kb16bitonly


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: July 22, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.