Forms Delphi

Title: How to create a zoom view
Question: How to create a zoom view
Answer:
//Put A TImage, TTimer and A TTrackBar On Your Form.
//TImage is called ZoomView here
//Set The TimerInterval to 150 ms or less
procedure TForm1.Timer1Timer(Sender: TObject);
var
AppRect, SourceRect: TRect;
Canvas : TCanvas;
Point : TPoint;
I : Integer;
Mag : Integer;
begin
//Check If Program Isn't IConic (= Minimized).
If not IsIconic(Application.Handle) Then
Begin
//Get The Coordinates Of The Application And Get The Cursor Position Of The Mouse Pointer.
AppRect := Rect(Self.Left,Self.Top,Self.Left+Self.Width,Self.Top+Self.Height);
GetCursorPos(Point);
//Check If The Mouse Pointer Is Outside Of The Mainform.
If not PtInRect(AppRect,Point) Then
Begin
//Create A Handle For The Desktop Window.
Canvas := TCanvas.Create;
Canvas.Handle := GetDC(GetDesktopWindow);
//Determine The Selected Magnitude (Var Mag).
//Use A TTrackBar For This (Called XZoom Here)
Mag := 0;
Case XZoom.Position of
1: Mag := 2;
2: Mag := 4;
3: Mag := 8;
4: Mag := 16;
5: Mag := 32;
6: Mag := 64;
End;
SourceRect := Rect(Point.X,Point.Y,Point.X,Point.Y);
//Inflate The Source Rectangle 's Width And Height
InflateRect(SourceRect,Round(ZoomView.Width/Mag),Round(ZoomView.Height/Mag));
//Paint The Source Rectangle To The Canvas Of The TImage
ZoomView.Canvas.CopyRect(ZoomView.BoundsRect,Canvas,SourceRect);
//Free The Memory Associated With The Canvas Variable.
Canvas.Free;
//Process The Messages Of Windows.
Application.ProcessMessages;
End;
End;
End;