用 GDI 操作 EMF 文件[4]: 重绘 EMF

本例效果图:

用 GDI 操作 EMF 文件[4]: 重绘 EMF

代码文件:

unit Unit1;



interface



uses

  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

  Dialogs, StdCtrls;



type

  TForm1 = class(TForm)

    Button1: TButton;

    procedure FormCreate(Sender: TObject);

    procedure FormDestroy(Sender: TObject);

    procedure FormMouseDown(Sender: TObject; Button: TMouseButton;

      Shift: TShiftState; X, Y: Integer);

    procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);

    procedure FormMouseUp(Sender: TObject; Button: TMouseButton;

      Shift: TShiftState; X, Y: Integer);

    procedure Button1Click(Sender: TObject);

  end;



var

  Form1: TForm1;



implementation



{$R *.dfm}



var

  HMetaFile: HENHMETAFILE;

  f: Boolean;

  x1,y1: Integer;

  R: TRect;



procedure TForm1.FormCreate(Sender: TObject);

const

  Path = 'C:\Temp\MyMetaFile.emf';

begin

  HMetaFile := GetEnhMetaFile(PChar(Path));

end;



procedure TForm1.FormDestroy(Sender: TObject);

begin

  DeleteEnhMetaFile(HMetaFile);

end;



procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;

  Shift: TShiftState; X, Y: Integer);

begin

  f := True;

  x1 := X;

  y1 := Y;

  R := Rect(x1,y1,X,Y);

end;



procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,

  Y: Integer);

begin

  if not f then Exit;

  DrawFocusRect(Canvas.Handle, R);

  R := Rect(x1,y1,X,Y);

  DrawFocusRect(Canvas.Handle, R);

  R := Rect(x1,y1,X,Y);

end;



procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton;

  Shift: TShiftState; X, Y: Integer);

begin

  f := False;

  PlayEnhMetaFile(Canvas.Handle, HMetaFile, R);

end;



procedure TForm1.Button1Click(Sender: TObject);

begin

  Refresh;

end;



end.


 
   
窗体文件:

object Form1: TForm1

  Left = 0

  Top = 0

  Caption = 'Form1'

  ClientHeight = 206

  ClientWidth = 339

  Color = clBtnFace

  Font.Charset = DEFAULT_CHARSET

  Font.Color = clWindowText

  Font.Height = -11

  Font.Name = 'Tahoma'

  Font.Style = []

  OldCreateOrder = False

  Position = poDesktopCenter

  OnCreate = FormCreate

  OnDestroy = FormDestroy

  OnMouseDown = FormMouseDown

  OnMouseMove = FormMouseMove

  OnMouseUp = FormMouseUp

  PixelsPerInch = 96

  TextHeight = 13

  object Button1: TButton

    Left = 256

    Top = 173

    Width = 75

    Height = 25

    Caption = 'Button1'

    TabOrder = 0

    OnClick = Button1Click

  end

end


 
   

你可能感兴趣的:(emf)