// variables
var Srect,Drect,PosForme:TRect;
iWidth,iHeight,DmX,DmY:Integer;
iTmpX,iTmpY:Real;
C:TCanvas;
hDesktop: Hwnd;
Kursor:TPoint;
// Magnify screen iff app is not iconic
If not IsIconic(Application.Handle) then begin
// Get cursor coordinates
GetCursorPos(Kursor);
hDesktop:= GetDesktopWindow;
// PosForm represents the rectangle with the
// Form (image control) coordinates.
PosForme:=Rect(Form1.Left,
Form1.Top,
Form1.Left+Form1.Width,
Form1.Top+Form1.Height);
//Show magnified screen //if cursor is outside the form.
If not PtInRect(PosForme,Kursor) then begin
// Code below is used to magnify selected
// portion of the screen. With a few
// modifications you could use
// it to shrink the screen
iWidth:=Image1.Width;
iHeight:=Image1.Height;
Drect:=Bounds(0,0,iWidth,iHeight);
iTmpX:=iWidth / (Slider.Position * 4);
iTmpY:=iHeight / (Slider.Position * 4);
Srect:=
Rect(Kursor.x,Kursor.y,Kursor.x,Kursor.y);
InflateRect(Srect,Round(iTmpX),Round(iTmpY));
//Retrieve a handle of a desktop window.
C:=TCanvas.Create;
try
C.Handle:=GetDC(GetDesktopWindow);
//Transfer part of the screen image on TImage.
Image1.Canvas.CopyRect(Drect,C,Srect);
finally
ReleaseDC(hDesktop, C.Handle);
C.Free;
end;
end;
// Be sure to process all Windows messages.
Application.ProcessMessages;
end; // IsIconic