Painting Pages and Zones (C++ Builder 6.0)

Take the following steps to add code to the existing project that will let you paint pages and zones:

1.

Start with the program you created in Working with Pages

2.

Add 2 buttons to your form and name them as follows:

 

Name

Caption

 

btnDrawZones

Draw Zones

 

btnDrawPage

Draw Page

3.

Add the following declaration to the public section of "Unit1.h":

 

bool bDrawPage;

bool bDrawZones;

4.

Update the FormCreate procedure to be as follows:

void __fastcall TForm1::FormCreate(TObject *Sender)
{
   CoCreateInstance ( CLSID_LEADRaster, 
        NULL, 
        CLSCTX_ALL, 
        IID_ILEADRaster, 
        (void**)&pLEADRasterObj ); 

   if ( pLEADRasterObj == NULL ) 
   {
      ShowMessage ( "Error Creating LEAD Raster Object" ); 
      Application->Terminate ( ); 
   }
   bDrawPage= False; 
   bDrawZones= False; 
}

5.

Update the btnAddPageClick procedure to be as follows:

void __fastcall TForm1::btnAddPageClick(TObject *Sender)
{
   int nRet; 
   int nPageNumber= 0; 

   nRet= LEADRasterIO1->Load ( pLEADRasterObj, AnsiToOLESTR("c:\\OCRTEST.gif"), 0, 0, 1 ); 

   if ( nRet != 0 ) 
      ShowMessage ( "Error loading file" ); 

   nRet= LEADRasterDocument1->AddPage ( pLEADRasterObj, nPageNumber ); 

   bDrawPage= False; 
   LEADRasterDocument1->set_ActivePageIndex ( 0 ); 
   bDrawPage= True; 

   if ( nRet == 0 ) 
   {
      ShowMessage ( "Page Width = " + IntToStr(LEADRasterDocument1->PageWidth [nPageNumber]) + "\n" +
              "Page Height = " + IntToStr(LEADRasterDocument1->PageHeight [nPageNumber]) + "\n" +
              "Page Bits Per Pixel = " + IntToStr(LEADRasterDocument1->PageBitsPerPixel [nPageNumber])); 
   }
   else
      ShowMessage ( "The engine could not add a new page to the Document" ); 
}

6.

Code the btnDrawZones button's click procedure as follows:

void __fastcall TForm1::btnDrawZonesClick(TObject *Sender) 
{
   bDrawZones= ! bDrawZones; 
}

7.

Code the btnDrawPage button's click procedure as follows:

void __fastcall TForm1::btnDrawPageClick(TObject *Sender) 
{
   if ( bDrawPage ) 
   {
      LEADRasterDocument1->set_EnableShowZones ( bDrawZones ); 
      LEADRasterDocument1->set_DrawPersistence ( False ); 
      LEADRasterDocument1->DrawPage( NULL, (long)this->Canvas->Handle, 0 ); 
   }
}

8.

Run your program to test it.