CMetaFile class

The CMetaFile class is derived from CMetaFileDC and allows you to easily load metafiles from disk and display them. A metafile can also be displayed with various alignment options, in order to preserve aspect ratio, etc. The class include serialization, allowing you to embed a metafile into a CDocument, for example.

To use the class, simply include "meta.h" and create an instance:

CMetaFile m_meta;

To load a metafile from disk use one of the CMetaFile::Read functions. One takes a pointer to a filename string, the other a pointer to a pre-opened CFile object. The Read function will return FALSE if an error occurred loading the metafile.

If you want to check if a file is a valid metafile, there is a static CMetaFile::IsMetaFile function you can call. Pass a CFile pointer and the function returns true if it's a valid metafile image.

That's about it. The example project shows how to embed a metafile in a document and display it from a view. Examples of all the alignment options are included.

Download Source. and an Example


  • I wanna Edit EPS File, Modify and Save a new EPS File

    Posted by Legacy on 01/22/2002 12:00am

    Originally posted by: Jes�s Lazo

    I wanna Edit EPS File, Modify and Save it in a new EPS File

    Help me please...

  • Bug in Serialize method of CMetaFile class. Memory leak!

    Posted by Legacy on 05/25/2001 12:00am

    Originally posted by: Borissenko Andrey

    ~~~~~~~~~~~~~~~~cut Serialize method~~~~~~~~~~~~~~~~~~~
    else {
    // Load
    // Get the header
    archive.Read(&m_aldusMFHeader, sizeof(m_aldusMFHeader));
    // Get the metafile bits size
    UINT nSize;
    archive >> nSize;
    if (nSize) {
    // Allocate a buffer
    //BYTE* pBits = (BYTE *)GlobalAllocPtr(GHND, nSize);
    BYTE* pBits = new BYTE [nSize];
    if (pBits) {
    // Read bits
    archive.Read(pBits, nSize);
    // Set metafile
    m_emf = ::SetEnhMetaFileBits(nSize, pBits);

    >>>>-----forget delete pBits here---->>>>>>>>>>

    delete [] pBits;

    >>>>-----forget delete pBits here---->>>>>>>>>>

    else {
    // Allocation error
    // Seek past bit data
    CFile* pFile = archive.GetFile();
    if (pFile)
    pFile->Seek(nSize, CFile::current);
    ~~~~~~~~~~~~~~~~ end cut Serialize method~~~~~~~~~~~~~~~~~~~

  • WMF from clipboard

    Posted by Legacy on 04/13/2001 12:00am

    Originally posted by: uk

    How can i get a meta file from the clipboard, i want to know the structure of the .wmf file data present in the clipboard.
    please let me know.

  • In case of vector wmf ??

    Posted by Legacy on 05/16/2000 12:00am

    Originally posted by: Lee young Sook

    I found that CMetaFile is excellent for image imported WMF.

    However if I try to draw Vector WMF(about 80KB big) on windows98, System resource went down to 0%(on using 'SetWinMetaFileBits' to conver WMF to EMF) and I couldn't see the file.

    If you know why, please reply me.

  • I wanna MetaFile To CBitmap Class

    Posted by Legacy on 07/09/1999 12:00am

    Originally posted by: empr

    I wanna MetaFile convert to CBitmap Class.

    help me.. ..Answer.

  • Viewing a metafile in a CFormView

    Posted by Legacy on 03/21/1999 12:00am

    Originally posted by: A Schwartz

    How could I insert a metafile (enhanced metafile) into a CFormView? Is it a similar process? Also, inside of the Formview resource, you can create an image of type "Enhanced Metafile", but unfortunately there is no way (that I know of) to import a metafile into the resource. Please respond either here with any suggestions or snippets at my e-mail ( Thank you!

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Moving from an on-premises environment to Office 365 does not remove the need to plan for disruptions or reduce the business risk requirements for protecting email services. If anything, some risks increase with a move to the cloud. Read how to ease the transition every business faces if considering or already migrating to cloud email. This white paper discusses: Setting expectations when migrating to Office 365 Understanding the implications of relying solely on Exchange Online security Necessary archiving …

  • Anthony Christie, the Chief Marketing Officer for Level Communications, is responsible for customer experience, worldwide marketing and product management. In this informative asset, he shares his insights into why a private network connection to cloud-bases applications is the right decision for your enterprise. Download now to find out more.

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date