随笔 - 2146  文章 - 97 评论 - 11767 trackbacks - 253

创建 EMF 文件, 并同时绘制在窗体.
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
const
  Path = 'C:\Temp\MyMetaFile.emf';
var
  MetaFileDC: HDC;         {EMF 画布句柄}
  HMetaFile: HENHMETAFILE; {EMF 文件句柄}
begin
  MetaFileDC := CreateEnhMetaFile(0, PChar(Path), nil, nil);
  Ellipse(MetaFileDC, 10, 10, 100, 60);
  HMetaFile := CloseEnhMetaFile(MetaFileDC);

  {在窗体上按原始大小绘制 EMF}
  PlayEnhMetaFile(Canvas.Handle, HMetaFile, Rect(10,10,100,60));

  DeleteObject(MetaFileDC);
  DeleteEnhMetaFile(HMetaFile);
end;

end.

posted on 2008-06-04 16:43  万一  阅读(...)  评论(...编辑  收藏