Click to See Complete Forum and Search --> : Who can help me with MetaFile?


Ying Wang
April 30th, 1999, 02:30 AM
Sir,
please tell me how to use the MetaFile File?
I can use the CMetaFileDC And the some Functions such as GetEnhMetaFile,
GetEnhMetaFileHeader and so on in VC6.0 to get some information from the
MetaFile file named "meta.emf",
but ,I can't use the information,because it's NULL!!!
now.this is my program:

HENHMETAFILE hemf=GetEnhMetaFile("meta.emf");
LPENHMETAHEADER lpmetahead=NULL;
UINT size=GetEnhMetaFileHeader(hemf,16384 ,lpmetahead);

but ,the variable size is NULL,and the pointer lpmetahead is NULL too.
I am puzzled. Because i tracke the program use Debug in VC6.0,I find the hemf is
not NULL.
how can i do?
I want to know what a MetaFile draw? how can i know it?
I mean my friend give me a file of MetaFile named meta.emf,I want to know what
my friend draw in the file.And I want use a program to judge what is draw in the file
automatically,How can i build the program?
At first, I want to judge the Description in the File.But I find the VC can't add the
Description in the file in convenience,the meta.emf has not Description.
so, i program to add the description, this is the code:


CRect rc;
GetClientRect(&rc);
HENHMETAFILE hMF;
CMetaFileDC dc;
BOOL bCreated =
dc.CreateEnhanced(
pDC,
"m1.emf",
0,
"XYZ Graphics Editor\0Bald Eagle\0\0"
);
if (!bCreated) return;
hMF=GetEnhMetaFile("meta.emf");
if (hMF==NULL) return;
PlayEnhMetaFile(dc.GetSafeHdc(),hMF,&rc);
HENHMETAFILE hemf= dc.CloseEnhanced();
pDC->PlayMetaFile(hemf, &rc);
pDC->SaveDC();
pDC->RestoreDC(-1);
if (hemf)
::DeleteEnhMetaFile(hemf);

so, i create a new file named m1.emf which is added the description.

but when i want to get the description string from the m1.emf ,i find it's none!!!!!
I use :
LPTSTR as;
hemf=GetEnhMetaFile("m1.emf");
if (hemf==NULL) return;
GetEnhMetaFileDescription(hemf,100000,as);
But i find the variable as can't be TextOut,and it's NULL!!!!!
why???
but how can i accomplish my idear?
please help me!
thanks!

by the way:
I am in China,I am chinese,so I connect the homepage so slowly.I wish you can mail to me.
my Email is
garden_wood@263.net
If you have some example about MetaFIle,would you are so kind to please give me a copy?
thanks.
//hehe My English is so poor, please don't laugh at me.
thanks!

Dave Lorde
April 30th, 1999, 04:54 AM
I tried your code with a .emf file I found on disk, and it works OK. I assume you do understand that calling GetEnhMetaFileHeader with a NULL LPENHMETAHEADER pointer just returns the header size, and you use this to allocate enough memory for the LPENHMETAHEADER before calling it again:


HENHMETAFILE hemf=GetEnhMetaFile("C:\\program files\\Common files\\microsoft shared\\Grphflt\\Ms.emf");
LPENHMETAHEADER lpmetahead=NULL;
UINT size = GetEnhMetaFileHeader(hemf, 0,lpmetahead);
lpmetahead = (LPENHMETAHEADER)new char[size];
size = GetEnhMetaFileHeader(hemf, size, lpmetahead);

// Use header here
...
delete[] lpmetahead; // Tidy up afterwards

If your code returns 0 for the size, the function has failed (maybe it couldn't find the file?). Under Windows NT, use GetLastError() to find the reason for failure.

Dave

Ying Wang
May 1st, 1999, 03:18 AM
Thank you sir,I have tried the program ,and I found it's work OK.
But the aim doesn't turn true.
I want to know the *.emf file containing what's Graphic,and how many in it.
I want to use PlayEnhMetaFileRecord function to transact the MetaFile Record in order to
know what's the graphic in the file.
But because the MSDN has no the Example,so I find it's too difficult.
Yesterday I find a Book named NT 4/Windows 95 Developer's HandBook,which is wrote by
Ben Ezzell and Jim Blaney of American. In the Book,it mentions some items about MetaFile.
of course,I use the book is Chinese Edit.
In it.I find the struct METARECORD is so good:

typedef struct tagMETARECORD { // mr
DWORD rdSize;
WORD rdFunction;
WORD rdParm[1];
} METARECORD;

the Book tell me the variable rdFunction is a function id.it's hight byte denotations
the number of parameters of transfering to the function,and the low byte denotations GDI
function.
so if the rdFunction is 0x0418,it's means

Metafile handle value handle ID variable

META_ELLIPSE 0x0418 18h 4

function's id is 18h,and the partameters'numbers is 4.
I think if i can get the value of rdFunction,now i can know the MetaFile will draw what's
graphic,so I will know the MetaFile File containing what's in it.

But how can i do it ?
maybe you can help me.
thank you very much!

Dave Lorde
May 4th, 1999, 04:12 AM
Sorry Ying, I don't know any more about using metafiles.

Dave