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



Comments

  • 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...

    Reply
  • 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~~~~~~~~~~~~~~~~~~~

    Reply
  • 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.

    Reply
  • 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.

    Reply
  • 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.


    Reply
  • 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 (anachnujr@aol.com). Thank you!

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

Top White Papers and Webcasts

  • Relying on outside companies to manage your network and server environments for your business and applications to meet the needs and demands of your users can be stressful. This is especially true as many Managed Hosting organizations fail to meet their service level agreements. Read this Forrester total economic impact report and learn what makes INetU different and how they exceed their customers' managed hosting expectations.

  • Today, users, applications, and data exist in more places than ever before, creating an unprecedented challenge for IT. How can IT achieve the flexibility and agility it needs to offer multiple types of applications in multiple locations? To better serve business demands for information everywhere, enterprises must develop new strategies for optimizing multiple kinds of networks. Read this white paper to learn how hybrid networks provide an unprecedented level of network dynamism, enterprise agility, and the …

Most Popular Programming Stories

More for Developers

RSS Feeds

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