home *** CD-ROM | disk | FTP | other *** search
- If you try to print (or show) .WMF-Files with Visual BASIC, you may
- run into the same problem as I did: I was not able to use some COREL-Draw
- Metafiles in Visual BASIC.
- The problem is that .WMF is not .WMF for all files. Some .WMF-Files are
- true Windows-Metafiles which can be used without any error, but most
- of the Files are in the ALDUS-PLACEABLE-METAFILE-Format (APM).
- I found a description about the problem in the new WIN SDK 3.1-Doc.
- It is listed below.
-
- Several months ago, I wrote a small DLL to use the APM-Files. There was
- an article in the Microsoft-Systems-Journal which had included a sample
- program.
-
- My extensions to that are the following:
-
- 1. I use a huge pointer to read the Metafile. Because of that I am
- able to read Metafiles larger than 64 kBytes
-
- 2. There is a function CreateMemhDC which creates a compatible Bitmap
- for a given Device-Context in memory (thanks to Charles Petzold's
- 'Programming Windows'). I "play the metafile into that Bitmap".
- The reason to do this is that you can simply copy the created
- Bitmap to your device via BITBLT. The Bitmap in memory has all
- the properties of the device, so you really 'draw on the device'.
-
- 3. The third function (CopyMemToDev) copies the memory Bitmap to the device.
- Try it with a big .WMF-File. (My example was a file with 196000 Bytes,
- a 20 MHz 386SX needs around 10 seconds to create the Bitmap in memory.
- But you can copy this Bitmap 10 times to the printer in 5 seconds.)
-
- 4. ClearMemhDC deletes the created Bitmap.
-
-
- Please find the DLL with the source and an example written in VisualBasic
- in this arcive. You may use the sources without any royalties.
-
- I'm not sure if the DLL handles ALL possible errors. Feel free to
- contact me at 100042,47.
-
-
- ********************* WINDOWS 3.1 DOC (courtesy of Microsoft) ************
-
- Using Windows Metafile Functions and Aldus Placeable Metafiles
-
- Summary
-
- Many Windows 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, and so on. 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. For more information regarding the
- APM format, call the Aldus Developer's Desk at (206) 622-5500 (ask for the
- third-party developer's desk). This number is correct as of 1/31/92.
- Please contact Aldus for its latest policy on distribution of information
- about the APM format.
-
-
- 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);
-
- }
-