Similar functions: Scalewindowextex, Scaleviewportextex
This example:
Code files:
UnitUnit1;InterfaceusesWindows, Messages, sysutils, variants, Classes, Graphics, Controls, Forms, Dialogs, Comctrls, Stdctrls;typeTForm1 =class(Tform)procedureFormcreate (Sender:tobject);procedureFormdestroy (Sender:tobject);procedureFormpaint (Sender:tobject);procedureFormmousedown (Sender:tobject; Button:tmousebutton; Shift:tshiftstate; X, Y:integer);procedureFormmousemove (Sender:tobject; Shift:tshiftstate; X, Y:integer);procedureFormmouseup (Sender:tobject; Button:tmousebutton; Shift:tshiftstate; X, Y:integer);End;varForm1:tform1;Implementation{$R *.DFM}varCvs:tcanvas; X1,y1:real; Wx,wy,vx,vy:integer; F:boolean;procedureTform1.formcreate (Sender:tobject);beginCVS: = tcanvas.create; Cvs. Handle: = GetDC (Handle); WX: = clientwidth; WY: = clientheight; VX: = WX; VY: = WY;End;procedureTform1.formmousedown (Sender:tobject; Button:tmousebutton; Shift:tshiftstate; X, Y:integer);beginF: = True; X1: = X; Y1: = Y;End;procedureTform1.formmousemove (Sender:tobject; Shift:tshiftstate; X, Y:integer);beginif notF ThenExit; X1: = x/x1; Y1: = y/y1; VX: = TRUNC (VX * x1); VY: = Trunc (VY * y1); Repaint; X1: = X; Y1: = Y;End;procedureTform1.formmouseup (Sender:tobject; Button:tmousebutton; Shift:tshiftstate; X, Y:integer);beginF: = False;End;procedureTform1.formpaint (Sender:tobject);ConstPts:Array[0..2] ofTpoint = ((X: -; Y:Ten), (X: -; Y: -), (X:Ten; Y: -));beginSetmapmode (CVS). Handle, Mm_anisotropic);{The following two functions can only be used in Mm_isotropic or Mm_anisotropic mode}Setwindowextex (CVS). Handle, WX, WY,Nil); Setviewportextex (CVS). Handle, VX, VY,Nil); Cvs. Pen.Width: =3; Cvs. Pen.color: = clred; Cvs. Brush.style: = Bscross; Cvs. Brush.color: = Clsilver; Cvs. Polygon (pts); Cvs. Ellipse ( -, -, -, the);End;procedureTform1.formdestroy (Sender:tobject);beginCvs. Free;End;End.
Form file:
ObjectForm1:tform1 left =0Top =0Caption =' Form1 'ClientHeight =241ClientWidth =302Color = Clbtnface Font.charset = Default_charset Font.Color = Clwindowtext Font.height =- OneFont.Name =' Tahoma 'Font.style = [] Oldcreateorder = False Position = Podesktopcenter OnCreate = formcreate OnDestroy = Formdestroy Onmou Sedown = Formmousedown OnMouseMove = Formmousemove OnMouseUp = formmouseup OnPaint = Formpaint PixelsPerInch = theTextHeight = -End
Http://www.cnblogs.com/del/archive/2008/06/02/1212382.html
To zoom out, just use these 2 functions: Setwindowextex, Setviewportextex