Cross Codebot Example: Magnify
Here is an example of a how to create simple screen magnifier utility using the Cross Codebot library. The application creates a small magnifier window which follows your mouse cursor. There's room for improvement with the application, such as moving the magnifier window when the mouse nears the screen edges, but overall was very easy to create.
Source Code
Below is a listing of the magnify application Main unit file.
unit Main;
{$mode delphi}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls,
Codebot.Graphics,
Codebot.Graphics.Types,
Codebot.Input.MouseMonitor;
{ TMainForm }
type
TMainForm = class(TForm)
Timer: TTimer;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure TimerTimer(Sender: TObject);
private
FSplash: ISplash;
FDesktop: ISurface;
procedure Capture(X, Y: Integer);
procedure MouseNotify(Kind: TMouseNotifyKind; Button: TMouseButton; X,
Y: Integer);
end;
var
MainForm: TMainForm;
implementation
{$R *.lfm}
{ TMainForm }
procedure TMainForm.FormCreate(Sender: TObject);
begin
FDesktop := NewSurface(TCanvas(nil));
FSplash := NewSplash;
FSplash.Bitmap.SetSize(200, 200);
with Mouse.CursorPos do
begin
Capture(X, Y);
FSplash.Move(X + 40, Y + 40);
end;
FSplash.Visible := True;
MouseMonitor.Add(MouseNotify);
Timer.Enabled := True;
end;
procedure TMainForm.FormDestroy(Sender: TObject);
begin
Timer.Enabled := False;
MouseMonitor.Remove(MouseNotify);
end;
procedure TMainForm.TimerTimer(Sender: TObject);
begin
with Mouse.CursorPos do
Capture(X, Y);
end;
procedure TMainForm.Capture(X, Y: Integer);
var
B: ISurface;
R: TRectI;
begin
R := FSplash.Bitmap.ClientRect;
R.Offset(X - 100, Y - 100);
R.Inflate(-66, -66);
B := FSplash.Bitmap.Surface;
B.Clear(clBlack);
FDesktop.CopyTo(R, B, FSplash.Bitmap.ClientRect, $FF, rqLowest);
B.StrokeRect(NewPen(clBlack), FSplash.Bitmap.ClientRect);
FSplash.Update;
end;
procedure TMainForm.MouseNotify(Kind: TMouseNotifyKind; Button: TMouseButton; X, Y: Integer);
begin
if Kind = nkMove then
FSplash.Move(X + 40, Y + 40);
end;
end.