ShowMagGlass example for C++ Builder

#define crNewCursor 10
// Global variable
bool gbLeftButton; 

void __fastcall TForm1::FormCreate(TObject *Sender) 
{
   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= (TCursor)crNewCursor; 

   // Starting the Magnifying Glass
   LEADImage1->StartMagGlass ( 100, 
                               100, 
                               400, 
                               (TColor)RGB(255, 0, 0), 
                               (TColor)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 ); 
}
//---------------------------------------------------------------------------
void __fastcall TForm1::LEADImage1MagGlassCursor(TObject *Sender) 
{
   // Check if the left button is not down and the Magnifying Glass is started
   if ((!gbLeftButton) && (LEADImage1->HasMagGlass)) 
   {
     Cursor= LEADImage1->MagGlassPointer; 
   }
}
//---------------------------------------------------------------------------

void __fastcall TForm1::LEADImage1MouseDown(TObject *Sender, 
      TMouseButton Button, TShiftState Shift, int X, int Y) 
{
   L_INT nStatus; 

   // Check if this is a left button and the Magnifying Glass is started
   if ((Button != mbLeft) || (!LEADImage1->HasMagGlass) ) 
     return; 

   // Move the Magnifying Glass to the hit position
   nStatus= LEADImage1->SetMagGlassPos (X, Y); 
   if ( nStatus != SUCCESS ) 
   {
     ShowMessage ( "Error while displaying Magnifying Glass. Error: " + IntToStr(nStatus) ); 
     return; 
   }

   // Show the Magnifying Glass
   nStatus= LEADImage1->ShowMagGlass (true); 
   if ( nStatus != SUCCESS ) 
   {
     ShowMessage ( "Error while displaying Magnifying Glass. Error: " + IntToStr(nStatus) ); 
     return; 
   }

   // Left button is currently pressed
   gbLeftButton= true; 

   // Call this Windows API function to hide the cursor
   ShowCursor ( false ); 
}
//---------------------------------------------------------------------------
void __fastcall TForm1::LEADImage1MouseMove(TObject *Sender, 
      TShiftState Shift, int X, int Y) 
{
   L_INT nStatus; 

   // Check if the left button is down and the Magnifying Glass is started
   if ( !LEADImage1->HasMagGlass ) 
     return; 

   // Move the Magnifying Glass to the mouse position
   nStatus= LEADImage1->SetMagGlassPos(X, Y); 
   if ( nStatus != SUCCESS ) 
      ShowMessage ( "Error while moving Magnifying Glass. Error: " + IntToStr(nStatus) ); 
}
//---------------------------------------------------------------------------
void __fastcall TForm1::LEADImage1MouseUp(TObject *Sender, 
      TMouseButton Button, TShiftState Shift, int X, int Y) 
{
   L_INT nStatus; 

   // Check if the left button is down and the Magnifying Glass is started
   if ((Button != mbLeft) || (!LEADImage1->HasMagGlass) ) 
      return; 

   // Show the Magnifying Glass
   nStatus= LEADImage1->ShowMagGlass ( false ); 
   if ( nStatus != SUCCESS ) 
      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 ); 
}
//---------------------------------------------------------------------------