Visual C++ 5.0 Syntax

In Version 5.0 of Visual C++, the MicroSoft Foundation Class (MFC) library provides an ActiveX interface. This topic describes how to use the interface with the LEADTOOLS ActiveX.

To add a LEAD RasterView control to your application, refer to the example in Loading and Displaying an Image.

Alternatively, to create an instance of the LEAD control at run time, use the Create function, which has the following prototype:

BOOL Create(

LPCTSTR lpszWindowName, DWORD dwStyle,

 

const RECT&rect, CWnd* pParentWnd, UINT nID,

 

CFile* pPersist = NULL, BOOL bStorage = FALSE,

 

BSTR bstrLicKey = NULL);

Provide parameters as follows:

lpszWindowName

Use "", because the control window does not need a name.

dwStyle

Use 0 for the default style.

&rect

Use the CRect function. For example: CRect(0,0,50,50).

pParentWnd

Use this to refer to the current window.

nID

Use 0 for the default ID.

pPersist

Use NULL.

bStorage

Use FALSE.

bstrLicKey

Use the LEADTOOLS license string, which is always the first line in the LTOCX14.LIC file. For example: "LEADTOOLS OCX Copyright (c) 1990-2005 LEAD Technologies, Inc." If you do not specify this string correctly, the ActiveX will not work when you distribute your application.

For example:

   CLEADRasterView *pRasView=NULL;
   static const WCHAR BASED_CODE _szLicString[] =
      L"LEADTOOLS OCX Copyright (c) 1990-2005 LEAD Technologies, Inc.";
   pRasView = new CLEADRasterView;
   // pass the license string to the CLEADRasterView::Create function.
   // The CLEADRasterView::Create expects a BSTR parameter and SysAllocString converts the
   // WCHAR[] to a BSTR
   BSTR lpLic = SysAllocString(_szLicString);
   pRasView->Create("", 0,CRect(0,0,50,50),this,0,NULL,FALSE,lpLic);
   pRasView->ShowWindow(SW_HIDE);
   SysFreeString(lpLic);

When getting or setting a property value, you must use a function that is created by adding a prefix to the property name.

To set a property value, the syntax is as follows:

m_controlname.Setpropertyname(value);

For example:

m_Lead1.SetRubberBandVisible(FALSE);

To get a property value, the syntax is as follows:

value = m_controlname.Getpropertyname();

For example:

HeightFactor = m_Lead1.GetBitmapHeight();

To set a property array value, the syntax is as follows:

m_controlname.Setpropertyname(index, value);

For example:

m_Lead1.SetRemapTable(MyIndex, (255 * Offset) / CurrentRange);

To get a property array value, the syntax is as follows:

value = m_controlname.Getpropertyname(index);

For example:

m_Lead1.SetBitmap(m_Lead1.GetColorPlanes(3)); // Copy the K plane

 

In Version 5.0 of Visual C++, the MicroSoft compiler also has a #import directive, which can be used to import type library information from an ActiveX control or COM Object.

To add any of the LEAD COM Objects to your application you can use the following:

// get information for ILEADRaster
   #import <ltr14n.dll> no_namespace, named_guids
// get information for ILEADRasterIO
   #import <ltrio14n.dll> no_namespace, named_guids

Then, you can create instances of the objects. The following shows how to create

an instance of ILEADRaster, which is licensed, and an instance of ILEADRasterIO, which is not. Note, you can also use IClassFactory2::CreateInstanceLic to create ILEADRaster objects.

   static const WCHAR BASED_CODE _szLicString[] =
      L"LEADTOOLS OCX Copyright (c) 1990-2005 LEAD Technologies, Inc.";
   BSTR lpLic = SysAllocString(_szLicString);
   ILEADRasterFactory *pFactory=NULL;
   ILEADRaster *pRaster=NULL;
   CoCreateInstance(CLSID_LEADRasterFactory, NULL, CLSCTX_ALL,
                    IID_ILEADRasterFactory, (void**)&pFactory);
   pRaster = (ILEADRaster*)pFactory->CreateObject("LEADRaster.LEADRaster.145", lpLic);
   SysFreeString(lpLic);//free the string
   pRaster->CreateBitmap(100.0f, 100.0f, 24);//create a bitmap
   pFactory->Release();//release the object
   pRaster->Release();//release the object

   ILEADRasterIO *pRasterIO=NULL;
   CoCreateInstance(CLSID_LEADRasterIO, NULL, CLSCTX_ALL,
                    IID_ILEADRasterIO, (void**)&pRasterIO);
   pRasterIO->put_EnableMethodErrors(FALSE);//1
   pRasterIO->PutEnableMethodErrors(FALSE); //2
   pRasterIO->EnableMethodErrors = FALSE;   //3
   pRasterIO->Load(m_LEADRasterView1.GetRaster(),
                   "v:\\images\\chess.bmp", 0, 1, 1);
   pRasterIO->Release();

Note that there are 3 different ways that you can access a COM Object's properties when you use the #import statement.

To set a property value, the syntax is as follows:

1) pObject->put_propertyname(value);
2) pObject->Putpropertyname(value);
3) pObject->propertyname = value;

For example:

   pRasterIO->put_EnableMethodErrors(FALSE);//1
   pRasterIO->PutEnableMethodErrors(FALSE); //2
   pRasterIO->EnableMethodErrors = FALSE;   //3

To get a property value, the syntax is as follows:

1) pObject->Get_propertyname(&value);
2) value = pObject->Getpropertyname();
3) value = pObject->propertyname;

For example:

   VARIANT_BOOL bVal;
   pRasterIO->get_EnableMethodErrors(&bVal); //1
   bVal = pRasterIO->GetEnableMethodErrors();//2
   bVal = pRasterIO->EnableMethodErrors;     //3