ShowMagGlass example for Delphi
Const
crNewCursor= 10;
// Global variables
var
gbLeftButton: Boolean;
procedure TForm1.FormCreate(Sender: TObject);
begin
LEADImage1.EnableMethodErrors:= False;
// Load 'Image1.cmp' file
LEADImage1.Load ( 'e:\image1.cmp', 0, 1, 1 );
// Load the Same Image in LEADImage2
LEADImage2.Load ( 'e:\image1.cmp', 0, 1, 1 );
// Invert the Bitmap
LEADImage2.Invert ( );
// Set the MagGlassFlags
LEADImage1.MagGlassFlags:= MAGGLASS_MANUAL_UPDATE;
// Load our cursor to be the MagGlass Curosr
Screen.Cursors[crNewCursor]:= LoadCursorFromFile ( 'e:\cursor1.cur' );
LEADImage1.MagGlassPointer:= crNewCursor;
// Starting the Magnifying Glass
LEADImage1.StartMagGlass ( 100,
100,
400,
RGB(255, 0, 0),
RGB(128, 128, 128),
False,
1,
False,
CROSSHAIR_FINE,
True,
True );
// Updating the Magnifying Glass bitmap of 1st control with bitmap of the
// 2nd control that has the same width and height.
LEADImage1.UpdateMagGlassFromHandle( LEADImage2.Bitmap, True );
end;
procedure TForm1.LEADImage1MagGlassCursor(Sender: TObject);
begin
// Check if the left button is not down and the Magnifying Glass is started
if ((Not gbLeftButton) And (LEADImage1.HasMagGlass)) Then
begin
Cursor:= LEADImage1.MagGlassPointer;
end;
end;
procedure TForm1.LEADImage1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
nStatus: L_INT;
begin
// Check if this is a left button and the Magnifying Glass is started
if ((Button <> mbLeft) Or (Not LEADImage1.HasMagGlass) ) then
Exit;
// Move the Magnifying Glass to the hit position
nStatus:= LEADImage1.SetMagGlassPos (x, y);
if ( nStatus <> SUCCESS ) then
begin
ShowMessage ( 'Error while displaying Magnifying Glass, Error: ' + IntToStr(nStatus) );
Exit;
end;
// Show the Magnifying Glass
nStatus:= LEADImage1.ShowMagGlass (True);
if ( nStatus <> SUCCESS ) then
begin
ShowMessage ( 'Error while displaying Magnifying Glass, Error: ' + IntToStr(nStatus) );
Exit;
end;
// Left button is currently pressed
gbLeftButton:= True;
// Call this Windows API function to hide the cursor
ShowCursor ( False );
end;
procedure TForm1.LEADImage1MouseMove(Sender: TObject; Shift: TShiftState;
X, Y: Integer);
var
nStatus: L_INT;
begin
// Check if the left button is down and the Magnifying Glass is started
if ( Not LEADImage1.HasMagGlass ) then
Exit;
// Move the Magnifying Glass to the mouse position
nStatus:= LEADImage1.SetMagGlassPos(x, y);
if ( nStatus <> SUCCESS ) Then
ShowMessage ( 'Error while moving Magnifying Glass. Error: ' + IntToStr(nStatus) );
end;
procedure TForm1.LEADImage1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
nStatus: L_INT;
begin
// Check if the left button is down and the Magnifying Glass is started
if ((Button <> mbLeft) Or (Not LEADImage1.HasMagGlass) ) then
Exit;
// Show the Magnifying Glass
nStatus:= LEADImage1.ShowMagGlass ( False );
if ( nStatus <> SUCCESS ) then
ShowMessage ( 'Error while hiding Magnifying Glass. Error: ' + IntToStr(nStatus) );
// Left button is released
gbLeftButton:= True;
// Call this Windows API function to show the cursor
ShowCursor ( True );
end;