Delphiマッピングモード実験

1640 ワード

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.