Delphi映射模式实验

unit FrmMappingMode;

interface

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

type
  TFrmMM = class(TForm)
    procedure FormPaint(Sender: TObject);
    procedure FormResize(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  FrmMM: TFrmMM;

implementation

{$R *.dfm}

procedure TFrmMM.FormPaint(Sender: TObject);
var
    halfH,halfW : integer;
begin
    halfH := clientHeight div 2;
    halfW := ClientWidth div 2;
    Canvas.Rectangle(1,1,100,200);

//    SetMapMode(canvas.Handle, MM_LOMETRIC);    //逻辑单位:0.1 mm
//    SetMapMode(canvas.Handle, MM_LOENGLISH);    //逻辑单位:0.1 inch
    SetMapMode(canvas.Handle, MM_ISOTROPIC);    // 1 = 1 自定义

    { SetWindowExtEx,SetViewportExtEx 函数只对
      MM_ANISOTROPIC 和 MM_ISOTROPIC映射模式有用,其它模式下它会被忽略}
    SetWindowExtEx(canvas.Handle,500,-500,nil);
    SetViewportExtEx(canvas.Handle,ClientWidth,ClientHeight,nil);
//  SetViewportExtEx(canvas.Handle,200,200,nil);

    SetViewportOrgEx(Canvas.Handle, ClientWidth div 2, ClientHeight div 2, nil);
    Canvas.Rectangle(0,0,50,50);
    //横线
    Canvas.MoveTo(-halfW,0);
    Canvas.LineTo(halfW,0);
    //竖线
    Canvas.MoveTo(0,-halfH);
    Canvas.LineTo(0,halfH);
end;

procedure TFrmMM.FormResize(Sender: TObject);
begin
    Invalidate;
end;

end.

  

posted @ 2015-01-14 17:18  庚武  Views(596)  Comments(0Edit  收藏  举报