看看这段程序对你是否有帮助<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br>{these hold important screen dimension information used when creating the reference rectangle}<br>WidthInMM,<br>HeightInMM,<br>WidthInPixels,<br>HeightInPixels: Integer;<br>{holds millimeter per pixel ratios}<br>MMPerPixelHorz,<br>MMPerPixelVer: Integer;<br>{the reference rectangle}<br>ReferenceRect: TRect;<br>{a handle to the metafile device context}<br>MetafileDC: HDC;<br>{the handle to a metafile}<br>TheMetafile: HENHMETAFILE;<br>{a handle to a brush used in drawing on the metafile}<br>TheBrush: HBRUSH;<br>OldBrush: HBRUSH;<br>begin<br>{the CreateEnhMetaFile function assumes that the dimensions in the reference<br>rectangle are in terms of .01 millimeter units (i.e., a 1 equals .01<br>millimeters, 2 equals .02 millimeters, etc.). therefore, the following<br>lines are required to obtain a millimeters per pixel ratio. this can then<br>be used to create a reference rectangle with the appropriate dimensions.}<br>{retrieve the size of the screen in millimeters}<br>WidthInMM:=GetDeviceCaps(Form1.Canvas.Handle, HORZSIZE);<br>HeightInMM:=GetDeviceCaps(Form1.Canvas.Handle, VERTSIZE);<br>{retrieve the size of the screen in pixels}<br>WidthInPixels:=GetDeviceCaps(Form1.Canvas.Handle, HORZRES);<br>HeightInPixels:=GetDeviceCaps(Form1.Canvas.Handle, VERTRES);<br>{compute a millimeter per pixel ratio. the millimeter measurements must be<br>multiplied by 100 to get the appropriate unit measurement that the<br>CreateEnhMetaFile is expecting (where a 1 equals .01 millimeters)}<br>MMPerPixelHorz:=(WidthInMM * 100) div WidthInPixels;<br>MMPerPixelVer:=(HeightInMM * 100) div HeightInPixels;<br>{create our reference rectangle for the metafile}<br>ReferenceRect.Top:=0;<br>ReferenceRect.Left:=0;<br>ReferenceRect.Right:=Image1.Width * MMPerPixelHorz;<br>ReferenceRect.Bottom:=Image1.Height * MMPerPixelVer;<br>{create a metafile that will be saved to disk}<br>MetafileDC:=CreateEnhMetaFile(Form1.Canvas.Handle, 'Example.emf',<br>@ReferenceRect,<br>'CreateEnhMetaFile Example Program'+Chr(0)+<br>'Example Metafile'+Chr(0)+Chr(0));<br>{display some text in the metafile}<br>TextOut(MetafileDC,15,15,'This is an enhanced metafile.',29);<br>{create a diagonal hatched brush and select it into the metafile}<br>TheBrush:=CreateHatchBrush(HS_DIAGCROSS, clRed);<br>OldBrush:=SelectObject(MetafileDC, TheBrush);<br>{draw a filled rectangle}<br>Rectangle(MetafileDC, 15, 50, 250, 250);<br>{delete the current brush}<br>SelectObject(MetafileDC, OldBrush);<br>DeleteObject(TheBrush);<br>{create a horizontal hatched brush and select it into the metafile}<br>TheBrush:=CreateHatchBrush(HS_CROSS, clBlue);<br>OldBrush:=SelectObject(MetafileDC, TheBrush);<br>{draw a filled ellipse}<br>Ellipse(MetafileDC, 15, 50, 250, 250);<br>{delete the current brush}<br>SelectObject(MetafileDC, OldBrush);<br>DeleteObject(TheBrush);<br>{close the metafile, saving it to disk and retrieving a handle}<br>TheMetafile:=CloseEnhMetaFile(MetafileDC);<br>{draw the metafile into the Image1 canvas}<br>PlayEnhMetaFile(Image1.Canvas.Handle, TheMetafile, Image1.Canvas.Cliprect);<br>{we are done with the metafile, so delete its handle}<br>DeleteEnhMetaFile(TheMetafile);<br>end;<br>end.<br>