Using the Magnifying Glass (C++ Builder)

Take the following steps to enable the generation of the MagGlassExt event and updating the zoomed image using the Internet COM object toolkit.

1.

Start C++ Builder.

2.

If you didn’t install LEAD Raster View Control, install it as follows:

 

On the Component pull-down menu, use the Import ActiveX Control… and select the LEAD Raster View Control (14.5). Press install.

3.

On the Project pull-down menu, use the Import Type library… and select the LEAD Raster Internet Object Library (14.5).

4.

On the Project pull-down menu, use the Import Type library… and select the LEAD Raster IO Object Library (14.5).

5.

Select the LEAD RasterView control; and add the control to your main form. Size and position the control, as you want it to appear at run time.

6.

From the ActiveX controls tab, add the LEAD Raster Inet, and LEAD Raster IO controls to your form.

7.

Add seven command buttons to your main form and name them as follows:

 

Name

Caption

 

btnStartUpServer

Start Up Server.

 

btnShutDownServer

Shut Server Down.

 

btnConnectToRemoteServer

Connect To Remote Server.

 

btnDisconnectFromRemoteServer

Disconnect From Remote Server.

 

btnLoadRemoteImage

Load Remote Image.

 

btnStartMagnifyingGlass

Start Magnifying Glass.

 

btnStopMagnifyingGlass

Stop Magnifying Glass.

8.

Add an Edit box to your main form and name it as follows:

 

Name

 

edtRemoteComputer.

9.

Set the Text property to the name of the computer you will use as a server.

10.

Declare the following in the Private section of “Unit1.h”.

    short hServer; //handle to server
    long gnCommandID;
    bool bMagGlass;

11.

Handle the Form1 OnCreate event, and code FormCreate procedure as follows. In online help, you can use the Edit pull-down menu to copy the block of code.

   void __fastcall TForm1::FormCreate(TObject *Sender)
{
    // Initialize some variables
   hServer = 0;
   gnCommandID = 0;
   bMagGlass = False;

   // Set defaults for displaying the image.
   // These are all persistent properties that can be set in the properties box.
   LEADRasterView1->Appearance = RASTERVIEW_APPEARANCE_FLAT;
   LEADRasterView1->BorderStyle = 1;
   LEADRasterView1->BackColor = (TColor)RGB(255, 255, 125);
   LEADRasterView1->PaintDither = PAINTDITHER_DIFFUSION;
   LEADRasterView1->PaintPalette = PAINTPALETTE_AUTO;
   LEADRasterView1->AutoRepaint = True;
   LEADRasterView1->AutoSize = False;
   LEADRasterView1->AutoSetRects = True;
   LEADRasterView1->PaintSizeMode = PAINTSIZEMODE_FIT;
   // Unlock support for the Inet object.
   // Stop generation of runtime exceptions for LEAD RasterView Control, LEAD
   // RasterIO Object Library and LEAD Raster Internet Object Library.
   LEADRasterView1->EnableMethodErrors = False;
   LEADRasterIO1->set_EnableMethodErrors ( false );
   LEADRasterInet1->set_EnableMethodErrors ( 0 );
}

12.

Handle the Form1 OnDestroy event, and code FormDestroy procedure as follows. In online help, you can use the Edit pull-down menu to copy the block of code.

void __fastcall TForm1::FormDestroy(TObject *Sender)
{
   short i; 
   //Disconnect all connections
   for (i = 0; i < LEADRasterInet1->ConnectListNum; i ++)
      LEADRasterInet1->InetDisconnect (LEADRasterInet1->get_ConnectList (i));

   if (bMagGlass)
      LEADRasterView1->StopMagGlass ();
}

13.

Code the btnStartUpServer button's click procedure as follows:

void __fastcall TForm1::btnStartUpServerClick(TObject *Sender) 
{
   int nRet; 
   //Initialize server on port 1000
   nRet= LEADRasterInet1->InetServerInit (1000);
hServer= LEADRasterInet1->InetServerHandle;
   if (nRet != 0)
      ShowMessage ("Error initializing server: " + IntToStr(nRet));
}

14.

Code the btnShutDownServer button's click procedure as follows:

void __fastcall TForm1::btnShutDownServerClick(TObject *Sender)
{
   int nRet;
   if (hServer != 0)
   {
      nRet= LEADRasterInet1->InetServerClose (hServer);

      if (nRet != 0)
         ShowMessage ("Error Shutting Down server: " + IntToStr(nRet));
      else
         hServer= 0;
   }
}

15.

Code the btnConnectToRemoteServer button's click procedure as follows:

void __fastcall TForm1::btnConnectToRemoteServerClick(TObject *Sender) 
{
   int nRet; 
   //Connect to remote computer on port 1000   nRet= LEADRasterInet1->InetConnect (AnsiToOLESTR(edtRemoteComputer->Text.c_str()), 1000);

   if (nRet != 0)
      ShowMessage ("Error connecting to " + edtRemoteComputer->Text + ": " + IntToStr(nRet));
}

16.

Code the btnDisconnectFromRemoteServer button's click procedure as follows:

void __fastcall TForm1::btnDisconnectFromRemoteServerClick(TObject *Sender) 
{
   int nRet; 
   /* We are assuming only one connection in this example.
    Therefore, the handle to the remote computer will be
    in the first position in the SendList*/
   nRet= LEADRasterInet1->InetDisconnect (LEADRasterInet1->get_SendList (0));
   if (nRet != 0)
      ShowMessage ("Error disconnecting from remote: " + IntToStr(nRet));
}

17.

Code the btnLoadRemoteImage button's click procedure as follows:

void __fastcall TForm1::btnLoadRemoteImageClick(TObject *Sender)
{
   int nRet;

   nRet= LEADRasterInet1->InetSendLoadCmd (999, AnsiToOLESTR("v:\\images\\Eagle.cmp"), 0, 1);

   if ((nRet != 0) && (nRet != ERROR_DATA_QUEUED))
      ShowMessage ("ERROR " + IntToStr(nRet) + " calling InetSendLoadCmd.");
}

18.

Code the btnStartMagnifyingGlass button's click procedure as follows:

void __fastcall TForm1::btnStartMagnifyingGlassClick(TObject *Sender)
{
   int nRet;

   if ((LEADRasterView1->Raster->Bitmap != 0) && (hServer == 0))
   {
        //Enable MagGlassExt event.
      if (LEADRasterView1->EnableMagGlassEvent == False)
         LEADRasterView1->EnableMagGlassEvent = True;

      LEADRasterView1->RgnFrameType = 0;

      //Start the Magnifying Glass
      nRet= LEADRasterView1->StartMagGlass (100, 100, 400, RGB(255, 0, 0), RGB(128, 128, 128), True, 1, False, CROSSHAIR_FINE, True, True);

      if (nRet == 0)
         bMagGlass= True;
   }
}

19.

Code the btnStopMagnifyingGlass button's click procedure as follows:

void __fastcall TForm1::btnStopMagnifyingGlassClick(TObject *Sender)
{
   int nRet;

   if ((LEADRasterView1->Raster->Bitmap != 0) && (hServer == 0))
   {
      nRet= LEADRasterView1->StopMagGlass ();

      if (nRet == 0)
         bMagGlass= false;
   }
}

20.

Handle the LEADRasterInet1 OnInetAccept event, and code LEADRasterInet1InetAccept as follows:

void __fastcall TForm1::LEADRasterInet1InetAccept (TObject *Sender, 
      short iServer) 
{
   int nRet; 
   short iComputer; 
   BSTR   bstrHostName; 
   AnsiString szHostName; 

   nRet= LEADRasterInet1->InetAcceptConnect (hServer); 
iComputer= LEADRasterInet1->InetConnectedComputer;
   if (nRet != 0) 
   {
      ShowMessage ("Error accepting connection: " + IntToStr(nRet)); 
      return; 
   }

   LEADRasterInet1->InetGetHostName(iComputer, HOST_NAME_DESCRP); 
bstrHostName= LEADRasterInet1-> InetHostName;
   //Add to our list
   LEADRasterInet1->set_SendList (LEADRasterInet1->SendListNum, iComputer ); 
   szHostName=bstrHostName; 
   ShowMessage ("Connection accepted from: " + szHostName); 
}

21.

Handle the LEADRasterInet1 OnInetConnected event, and code LEADRasterInet1InetConnected as follows:

void __fastcall TForm1::LEADRasterInet1InetConnected (TObject *Sender, 
      short iComputer ) 
{
   BSTR  bstrHostName; 
   AnsiString szHostName; 

   //Get remote host name
   LEADRasterInet1->InetGetHostName (iComputer, HOST_NAME_DESCRP); 
bstrHostName= LEADRasterInet1-> InetHostName;
   //Add this connection to our SendList
   LEADRasterInet1->set_SendList (LEADRasterInet1->SendListNum, iComputer ); 
   szHostName= bstrHostName; 
   ShowMessage ("Successfully connected to remote computer: " + szHostName ); 
}

22.

Handle the LEADRasterInet1 OnInetDisconnected event, and code LEADRasterInet1InetDisconnected as follows:

void __fastcall TForm1::LEADRasterInet1InetDisconnected(TObject *Sender, 
      short iComputer) 
{
   if (hServer == 0) 
      ShowMessage ("Disconnect from remote server");
   else
      ShowMessage ("Connection to remote computer closed");
}

23.

Handle the LEADRasterInet1 OnInetReceiveCmd event, and code LEADRasterInet1InetReceiveCmd as follows:

void __fastcall TForm1::LEADRasterInet1InetReceiveCmd(TObject *Sender,
      short iComputer, short InetCommand, long nCommandID, short nError,
      ILEADRasterInetPacket *Params, long nExtraDataSize,
      ILEADRasterVariant *pExtraData)
{
   BSTR bstrName;
   ILEADRasterVariant* pColorBuffer= NULL;
   ILEADRasterVariant* pString= NULL;

   CoCreateInstance( CLSID_LEADRasterVariant,
                     NULL,
                     CLSCTX_ALL,
                     IID_ILEADRasterVariant,
                     (void**)&pColorBuffer);

   CoCreateInstance( CLSID_LEADRasterVariant,
                     NULL,
                     CLSCTX_ALL,
                     IID_ILEADRasterVariant,
                     (void**)&pString);
   int nStatus= ERROR_FEATURE_NOT_SUPPORTED;

   if (nError != 0)
      nStatus= ERROR_TRANSFER_ABORTED;
   else
   {
      switch (InetCommand)
      {
         case INETCMD_LOAD:
         {
            //check the validity of the parameters
            if ((Params->ParamCount == 4) &&
                (Params->get_ParamType(0) == PARAM_TYPE_STRING) &&
                (Params->get_ParamType(1) == PARAM_TYPE_INT32) &&
                (Params->get_ParamType(2) == PARAM_TYPE_INT32) &&
                (Params->get_ParamType(3) == PARAM_TYPE_UINT32))
            {
               nStatus= LEADRasterIO1->Load(LEADRasterView1->Raster,
      Params->get_ParamValue(0)->StringValue,
      Params->get_ParamValue(1)->LongValue,
      1,
      1);

               if (nStatus != 0)
                  ShowMessage ("Load Bitmap failed with error code: " + IntToStr(nStatus));
               else
               {
                  nStatus= LEADRasterInet1->InetSendBitmap(LEADRasterView1->Raster, FILE_CMP, 0, QFACTOR_PQ2);

                  if (nStatus != 0)
                     ShowMessage ("SendBitmap failed with error code: " + IntToStr(nStatus));
               }
            }
            else
               nStatus= ERROR_INV_PARAMETER;    //Invalid parameters

            LEADRasterInet1->InetSendLoadRsp(nCommandID, 0, 0, NULL, (short)nStatus);
            return;
         }

         case INETCMD_GET_MAGGLASS_DATA:
         {
            //check the validity of the parameters
            if ((Params->ParamCount == 5) && (Params->get_ParamType(0) == PARAM_TYPE_UINT32)
               && (Params->get_ParamType(1) == PARAM_TYPE_UINT32) && (Params->get_ParamType(2) == PARAM_TYPE_USTRING)
               && (Params->get_ParamType(3) == PARAM_TYPE_INT32) && (Params->get_ParamType(4) == PARAM_TYPE_INT32))
            {
               if (LEADRasterView1->Raster->Bitmap != 0)
               {
                  pString->Type = VALUE_STRING;
                  pString->set_StringValue ( Params->get_ParamValue(2)->StringValue );
                  nStatus= LEADRasterInet1->InetGetMagGlassData(LEADRasterView1->Raster,
       pColorBuffer,
        pString,
        Params->get_ParamValue(3)->LongValue,
        Params->get_ParamValue(4)->LongValue);
                  if (nStatus != 0)
                      ShowMessage ("InetGetMagGlassData failed with error code: " + IntToStr(nStatus));
               }
               else
                  nStatus= ERROR_INV_PARAMETER;   //Invalid parameter
            }
            else
              nStatus= ERROR_INV_PARAMETER;    //Invalid parameters
            pString->Type = VALUE_STRING;
            pString->set_StringValue ( Params->get_ParamValue(2)->StringValue );
            LEADRasterInet1->InetSendGetMagGlassDataRsp(nCommandID,
                  pColorBuffer,
                  pString,
                  Params->get_ParamValue(3)->LongValue,
                  Params->get_ParamValue(4)->LongValue,
                  0,
                  NULL,
                   (short)nStatus);
            return;
         }
      }
   }

   if ( pColorBuffer )
      pColorBuffer->Release ( );

   if ( pString )
      pString->Release ( );

   LEADRasterInet1->InetSendRsp((InetCmdType)InetCommand, nCommandID, NULL, 0, NULL, (short)nStatus);
}

24.

Handle the LEADRasterInet1 OnInetReceiveRsp event, and code LEADRasterInet1InetReceiveRsp as follows:

void __fastcall TForm1::LEADRasterInet1InetReceiveRsp (TObject *Sender, 
      short iComputer, short InetCommand, long nCommandID, short nError, 
      short nStatus, ILEADRasterInetPacket *Params, long nExtraDataSize, 
      Variant ExtraData) 
{
   int nRet; 

   if (nError != 0) 
      return;

   switch (InetCommand)
   {
      case INETCMD_LOAD:
      {
         if (nStatus != 0)
            ShowMessage ("Load failed with error code: " + IntToStr(nStatus));
      }
      break;

      case INETCMD_GET_MAGGLASS_DATA:
      {
         if (nStatus == 0)
         {
            if ((Params->ParamCount == 6) &&
                (Params->get_ParamType(0) == PARAM_TYPE_UINT32) &&
                (Params->get_ParamType(1) == PARAM_TYPE_USTRING) &&
                (Params->get_ParamType(2)== PARAM_TYPE_UINT32) &&
                (Params->get_ParamType(3) == PARAM_TYPE_USTRING) &&
                (Params->get_ParamType(4)== PARAM_TYPE_INT32) &&
                (Params->get_ParamType(5) == PARAM_TYPE_INT32))
               {
                  nRet= LEADRasterView1->UpdateMagGlass (Params->get_ParamValue(1), Params->get_ParamValue(3), Params->get_ParamValue(4).lVal, Params->get_ParamValue(5).lVal, true);

                  if (nRet != 0)
                     ShowMessage ("UpdateMagGlass failed with error code: " + IntToStr(nRet));
               }
               else
                  ShowMessage ("Invalid parameter passed to INETCMD_GET_MAGGLASS_DATA response");
         }
         else
            ShowMessage ("Get MagGlass Data from server with error code " + IntToStr(nStatus));
      }
      break;
   }
}

25.

Code the LEADRasterView1’s OnMagGlassExt event as follows:

void __fastcall TForm1::LEADRasterView1MagGlassExt(TObject *Sender, 
      long nMaskPlaneStart, long nMaskPlaneEnd, ILEADRasterVariant* pvMaskPlane) 
{
   int nRet; 

   gnCommandID++;

   nRet= LEADRasterInet1->InetSendGetMagGlassDataCmd (gnCommandID, 0, pvMaskPlane, nMaskPlaneStart, nMaskPlaneEnd); 

   if ((nRet != 0) && (nRet != ERROR_DATA_QUEUED)) 
      ShowMessage ("ERROR " + IntToStr(nRet) + " calling InetSendGetMagGlassDataCmd."); 

}

26.

At the beginning of the Unit1.h file, include this file:

#include "E:\LEAD14\Dist\include\L_OcxErr.h"  /* change the path to be compatible with the file in your PC*/

27.

Run the exe file two times to execute two applications.

28.

In the first application press the Start Up Server button.

29.

In the second application fill the edit box with the IP Address of the Remote computer on which you ran the first application as Server, then press the Connect To Remote Server button to connect to the specified address.

30.

After that, press the Load Remote Image button of application number two to load an image on the Server. Then press the Start Magnifying Glass button to start the magnifying glass with Internet support. Press the left key and move over the image to see the zoomed area using the Magnifying Glass with Internet support.