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 RasterView Control, install it.

 

On the Component pull-down menu, use the Import ActiveX Control… and select the LEAD RasterView Control (14.5), and 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 Object Library (14.5)

5.

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

6.

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

7.

If you didn’t install LEvntSnk, install it.

 

On the Component pull-down menu, use install component …, and browse to LEADXX\Include\LEvntSnk.pas, and press Ok.

8.

Open the LEvntSnk.hpp file and delete those lines from the TLEADAbstractEventSink class.

private:
void *__IDispatch; /* IDispatch */

public:
operator IDispatch*(void) { return (IDispatch*)&__IDispatch; }
operator IUnknown*(void) { return (IUnknown*)&__IDispatch; }

 

and save the file.

9.

From the ActiveX controls, Add the LEvntSnk control to your form.

10.

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

 

Name

Caption

 

StartUpServer

Start Up Server

 

ShutDownServer

Shut Server Down

 

ConnectToRemoteServer

Connect To Remote Server

 

DisconnectFromRemoteServer

Disconnect From Remote Server

 

LoadRemoteImage

Load Remote Image

 

StartMagnifyingGlass

Start Magnifying Glass

 

StopMagnifyingGlass

Stop Magnifying Glass

11.

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

 

Name

 

RemoteComputer

12.

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

13.

Declare the following in the Private section of Unit1.h

short hServer; //handle to server
long gnCommandID;
bool bMagGlass;
LEADRasterIO* pRasterIO;
LEADRasterInet* pLEADNet1; 

14.

Add the following initialization code to the main form's Show procedure. In online help, you can use the Edit pull-down menu to copy the block of code.

void __fastcall TForm1::FormShow(TObject *Sender)
{
LEADRaster* pLEADRas= NULL;

// 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;

 // Create the Raster IO and Raster Inet objects
CoCreateInstance(CLSID_LEADRasterIO, NULL, CLSCTX_ALL, IID_ILEADRasterIO, (void**)&pRasterIO);
CoCreateInstance(CLSID_LEADRasterInet, NULL, CLSCTX_ALL, IID_ILEADRasterInet, (void**)&pLEADNet1);
LEADEventSink1->Connect (pLEADNet1, DIID__LTRASINETEvents);

// Create a temp LEADRaster object and use it
// to unlock support for the Inet object
 CoCreateInstance(CLSID_LEADRaster, NULL, CLSCTX_ALL, IID_ILEADRaster, (void**)&pLEADRas);
pLEADRas->Release();
// Stop generation of runtime exceptions for LEAD RasterView Control, LEAD
// RasterIO Object Library and LEAD Raster Internet Object Library.
LEADRasterView1->EnableMethodErrors = False;
pRasterIO->EnableMethodErrors= False;
pLEADNet1->EnableMethodErrors = 0;
}

15.

Code the main form's Close procedure as follows:

void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
{
 short i;
//Disconnect all connections
pLEADNet1->ConnectListNum;
for (i = 0; i < pLEADNet1->ConnectListNum; i ++)
 pLEADNet1->InetDisconnect (pLEADNet1->get_ConnectList (i));

 if (bMagGlass)
 LEADRasterView1->StopMagGlass ();

 if (pLEADNet1)
  pLEADNet1->Release();
 if (pRasterIO)
  pRasterIO->Release();

}

16.

Code the StartUpServer button's click procedure as follows:

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

17.

Code the ShutDownServer button's click procedure as follows:

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

 if (hServer != 0)
{
 nRet= pLEADNet1->InetServerClose ((short)hServer);

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

18.

Code the LEADEventSink1 OnInvoke event as follows:

void __fastcall TForm1::LEADEventSink1Invoke(TObject *Sender, int DispID,
const TGUID &IID, int LocaleID, WORD Flags, tagDISPPARAMS &Params,
Pointer varResult, Pointer ExcepInfo, Pointer ArgErr)
{
short hComputer;
BSTR hName;
int nRet;
short iComputer;
BSTR sRemote;
int nStatus;
ILEADRasterVariant* vColorBuffer= NULL;
ILEADRasterVariant* vString= NULL;
int InetCommand;
int nCommandID;
int nError;
LEADRasterInetPacket* nParams;
AnsiString strTemp;

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

CoCreateInstance( CLSID_LEADRasterVariant,
     NULL,
    CLSCTX_ALL,
    IID_ILEADRasterVariant,
    (void**)&vString);
 switch (DispID)
{

 case LEADRASTERINETEVENTS_INETACCEPT:
{
  nRet= pLEADNet1->InetAcceptConnect ((short)hServer);
   hComputer= pLEADNet1->InetConnectedComputer;

  if (nRet != 0)
{
  ShowMessage ("Error accepting connection: " + IntToStr(nRet));
  return;
  }

  pLEADNet1->InetGetHostName ((short)hComputer, HOST_NAME_DESCRP);
   hName= pLEADNet1->InetHostName;
   //Add to our list
  pLEADNet1->set_SendList(pLEADNet1->SendListNum, hComputer);
strTemp = hName;
  ShowMessage ("Connection accepted from: " + strTemp);
}
break;

case LEADRASTERINETEVENTS_INETCONNECTED:
{

 iComputer= (OleVariant)(Params.rgvarg[0]);
   //Get remote host name
  pLEADNet1->InetGetHostName (iComputer, HOST_NAME_DESCRP);
   sRemote= pLEADNet1->InetHostName;

  //Add this connection to our SendList
  pLEADNet1->set_SendList (pLEADNet1->SendListNum, iComputer);
strTemp = sRemote;
  ShowMessage ("Successfully connected to remote computer: " + strTemp);
}
break;

case LEADRASTERINETEVENTS_INETDISCONNECTED:
{
  if (hServer == 0)
  ShowMessage ("Disconnect from remote server");
  else
  ShowMessage ("Connection to remote computer closed");
 }
break;

case LEADRASTERINETEVENTS_INETRECEIVECMD:
{
 InetCommand= (OleVariant)(Params.rgvarg[5]);
nCommandID= (OleVariant)(Params.rgvarg[4]);
nError= (OleVariant)(Params.rgvarg[3]);
nParams = (LEADRasterInetPacket*)(Params.rgvarg[2].pdispVal);

   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 ((nParams->ParamCount == 4) &&
  (nParams->get_ParamType(0) == PARAM_TYPE_STRING) &&
(nParams->get_ParamType(1) == PARAM_TYPE_INT32) &&
(nParams->get_ParamType(2) == PARAM_TYPE_INT32) &&
(nParams->get_ParamType(3) == PARAM_TYPE_UINT32))
{

 nStatus= pRasterIO->Load( LEADRasterView1->Raster,
    nParams->get_ParamValue(0)->StringValue,
   (short)nParams->get_ParamValue(1)->LongValue,
   1,
   1 );

 if (nStatus != 0)
  ShowMessage ("Load Bitmap failed with error code: " + IntToStr(nStatus));
 else
 {
  nStatus= pLEADNet1->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

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

case INETCMD_GET_MAGGLASS_DATA:
{
 //check the validity of the parameters
 if ((nParams->ParamCount == 5) && (nParams->get_ParamType(0) == PARAM_TYPE_UINT32)
  && (nParams->get_ParamType(1) == PARAM_TYPE_UINT32) && (nParams->get_ParamType(2) == PARAM_TYPE_USTRING)
 && (nParams->get_ParamType(3) == PARAM_TYPE_INT32) && (nParams->get_ParamType(4) == PARAM_TYPE_INT32))
 {
  if (LEADRasterView1->Raster->Bitmap != 0)
{
    vString->set_Type ( VALUE_STRING );
    vString->StringValue= nParams->get_ParamValue(2)->StringValue;

 nStatus= pLEADNet1->InetGetMagGlassData(LEADRasterView1->Raster,
     vColorBuffer,
     vString,
     nParams->get_ParamValue(3)->LongValue,
     nParams->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
        vString->set_Type ( VALUE_STRING );
       vString->StringValue= nParams->get_ParamValue(2)->StringValue;

  pLEADNet1->InetSendGetMagGlassDataRsp(nCommandID,
   vColorBuffer,
   vString,
   nParams->get_ParamValue(3)->LongValue,
   nParams->get_ParamValue(4)->LongValue,
   0,
   NULL,
   (short)nStatus);
 return;
   }
}
}
pLEADNet1->InetSendRsp((InetCmdType)InetCommand, nCommandID, NULL, 0, NULL, (short)nStatus);
}
break;

case LEADRASTERINETEVENTS_INETRECEIVEBITMAP:
{
   LEADRasterView1->Raster->Bitmap = (long)(Params.rgvarg[0].lVal);
}
break;

  case LEADRASTERINETEVENTS_INETRECEIVERSP:
{
 InetCommand= (OleVariant)(Params.rgvarg[6]);
nError= (OleVariant)(Params.rgvarg[4]);
nStatus= (OleVariant)(Params.rgvarg[3]);
nParams = (LEADRasterInetPacket*)(Params.rgvarg[2].pdispVal);

  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 ((nParams->ParamCount == 6) &&
  (nParams->get_ParamType(0) == PARAM_TYPE_UINT32) &&
(nParams->get_ParamType(1) == PARAM_TYPE_USTRING) &&
(nParams->get_ParamType(2)== PARAM_TYPE_UINT32) &&
(nParams->get_ParamType(3) == PARAM_TYPE_USTRING) &&
(nParams->get_ParamType(4)== PARAM_TYPE_INT32) &&
(nParams->get_ParamType(5) == PARAM_TYPE_INT32))
 {
  nRet= LEADRasterView1->UpdateMagGlass (nParams->get_ParamValue(1),
   nParams->get_ParamValue(3),
   nParams->get_ParamValue(4)->LongValue,
   nParams->get_ParamValue(5)->LongValue,
   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;
}
}
break;
}
 if (vColorBuffer)
{
 vColorBuffer ->Release ( );
 vColorBuffer= NULL;
}
 if (vString)
{
 vString ->Release ( );
 vString = NULL;
}
}

19.

Code the ConnectToRemoteServer button's click procedure as follows:

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

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

20.

Code the DisconnectFromRemoteServer button's click procedure as follows:

void __fastcall TForm1::DisconnectFromRemoteServerClick(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= pLEADNet1->InetDisconnect (pLEADNet1->get_SendList (0));
 if (nRet != 0)
 ShowMessage ("Error disconnecting from remote: " + IntToStr(nRet));
}

21.

Code the LoadRemoteImage button's click procedure as follows:

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

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

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

22.

Code the StartMagnifyingGlass button's click procedure as follows:

void __fastcall TForm1::StartMagnifyingGlassClick(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;
 }
}

23.

Code the StopMagnifyingGlass button's click procedure as follows:

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

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

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

24.

Code the LEADRasterView1’s MagGlassExt event as follows:

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

 gnCommandID++;

nRet= pLEADNet1->InetSendGetMagGlassDataCmd (gnCommandID, 0, (ILEADRasterVariant*)pvMaskPlane, nMaskPlaneStart, nMaskPlaneEnd);

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

25.

At the beginning of the Unit1.h file, include those files:

#include "LEADRasterInetLib_TLB.h"
#include "LTRASTERLib_TLB.h"
#include "LTRASTERIOLib_TLB.h"
#include "f:\lead14\dist\include\L_OcxErr.h" /* change the path to be compatible with the file in your PC*/

26.

Run the exe file two times to execute two applications.

27.

In the first application press Start Up Server button.

28.

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

29.

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