How to read an old Windows Meta File?

David Webber 136 Reputation points
2020-11-17T17:24:38.497+00:00

I am reading Enhanced Meta Files with ::GetEnhMetaFile( pszFilename ) which returns a HENHMETAFILE handle.

But I want to read the old fashioned Windows Meta Files too. Can anyone tell me how to do this???

I am going round in circles with the docuemtation.

GetMetaFile

The docs tell me that ::GetMetaFile( pszFilename ) does the job, but also that "GetMetaFile is no longer available for use as of Windows 2000. Instead, use GetEnhMetaFile".

GetEnhMetaFile

The documentation for GetEnhMetaFile says:

"A Windows-format metafile must be converted to the enhanced format before it can be processed by the GetEnhMetaFile function. To convert the file, use the SetWinMetaFileBits function."

SetWinMetaFileBits

So I look at SetWinMetaFileBits(). IT has a number of arguments, none of which is a file name but including "A pointer to a buffer that contains the Windows-format metafile data. (It is assumed that the data was obtained by using the GetMetaFileBitsEx or GetWinMetaFileBits function.)"

Now SetWinMetaFileBits() returns an HENMETAFILE handle which is great, but if I have that, then I don't need GetEnhMetaFile() so what was that about? Furthermore

GetWinMetaFileBits

takes an HENHMETAFILE as an argument, and fills in a buffer with Win Meta File format data; But haven't got an HENHMETAFILE.

GetMetaFileBitsEx

fills in a data buffer in WMF format, if you have an HMETAFILE. But to get an HMETAFILE from my file on disk, the obvious way is to use GetMetaFile() but...

There's a hole in my bucket?

Dave

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,682 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,785 questions
{count} vote

Accepted answer
  1. RLWA32 45,941 Reputation points
    2020-11-17T17:37:01.803+00:00

    Check out this thread (I haven't tested the solution) - convert-wmf-file-to-emf-file-with-setwinmetafilebits-api-in-c

    1 person found this answer helpful.

2 additional answers

Sort by: Most helpful
  1. David Lowndes 4,721 Reputation points
    2020-11-17T17:53:51.677+00:00

    Gdiplus seems to be able to load a WMF file.

    >

    GdiplusStartupInput gdiplusStartupInput;
    ULONG_PTR gdiplusToken;
    GdiplusStartup( &gdiplusToken, &gdiplusStartupInput, NULL );

    Metafile gdimf( Path to a WMF file );
    GdiplusShutdown( gdiplusToken );


  2. Castorix31 86,311 Reputation points
    2020-11-17T18:44:03.907+00:00

    There are several ways to load/display WMF
    A simple one is with OleLoadPicture

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.