void wmftobmp(int width,int height,char *metafile)
{
//width为图片宽度,height为图片高度,*metafile为元文件名
static hmetafile hmf;
char num[4];
file *fh;
hdc hmemdc;
hbitmap hbmp,hold;
bitmapfileheader hdr;
lpbitmapinfoheader lpbmpih;
hglobal hg;
bitmapcount++;
if(bitmapcount==3)
{
width=128;
height=132;
}
if(bitmapcount==1)
{
width=80;
height=50;
}
tostring10(bitmapcount,num);
//把字符串转换成数字的函数
lstrcpy(bmpfile,filepath);
lstrcat(bmpfile,num);
lstrcpy(giffile,bmpfile);
lstrcat(bmpfile,".bmp");
lstrcat(giffile,".gif");
hmf=getmetafile(metafile);
hdisplaydc=createdc("display",null,null,null);
hmemdc=createcompatibledc(hdisplaydc);
hg=globalalloc(ghnd,sizeof(bitmapinfoheader));
lpbmpih=(lpbitmapinfoheader)globallock(hg);
lpbmpih->bisize=sizeof(bitmapinfoheader);
lpbmpih->biwidth=width;
lpbmpih->biheight=height;
lpbmpih->biplanes=1;
lpbmpih->bibitcount=8;
lpbmpih->bicompression=0;
hbmp=createcompatiblebitmap(hdisplaydc,width,height);
globalunlock(hg);
globalfree(hg);
hold=selectobject(hmemdc,hbmp);
setmapmode(hmemdc,mm_anisotropic);
setwindoworgex(hmemdc,0,0,null);
setviewportextex(hmemdc,width,height,null);
playmetafile(hmemdc,hmf);
hbmp=selectobject(hmemdc,hold);
if((fh=fopen(bmpfile,"w+b"))==null)
{
return;
}
hdr.bftype=0x4d42;
hdr.bfsize=sizeof(bitmapfileheader)+sizeof(bitmapinfoheader)+256*sizeof(rgbquad)+width*height;
hdr.bfreserved1=0;
hdr.bfreserved2=0;
hdr.bfoffbits=sizeof(bitmapfileheader)+sizeof(bitmapinfoheader)+256*sizeof(rgbquad);
fwrite((lpstr)&hdr,sizeof(bitmapfileheader),1,fh);
hg=globalalloc(ghnd,sizeof(bitmapinfoheader)+256*sizeof(rgbquad));
lpbmpih=(lpbitmapinfoheader)globallock(hg);
lpbmpih->bisize=sizeof(bitmapinfoheader);
lpbmpih->biwidth=width;
lpbmpih->biheight=height;
lpbmpih->biplanes=1;
lpbmpih->bibitcount=8;
lpbmpih->bicompression=0;
lpbmpih->bisizeimage=width*height;
lpbmpih->biclrused=256;
lpbmpih->biclrimportant=0;
j=getdibits(hmemdc,hbmp,0,height,null,(bitmapinfo*)lpbmpih,dib_rgb_colors);
lpbmpih->bisize=sizeof(bitmapinfoheader);
fwrite(lpbmpih,sizeof(bitmapinfoheader)+256*sizeof(rgbquad),1,fh);
getdibits(hmemdc,hbmp,0,height,(lpstr)filebuffer,(bitmapinfo*)lpbmpih,dib_rgb_cols);
fwrite(filebuffer,width*height,1,fh);
globalunlock(hg);
globalfree(hg);
fclose(fh);
deletedc(hmemdc);
deletedc(hdisplaydc);
deleteobject(hbmp);
deleteobject(hold);
deletemetafile(hmf);
}//end function wmftobmp()