FilePage Event Example for C++ Builder

This example shows how the FilePage event can be used to size and position a RasterView Control when an image is loaded.

LEADRasterIO* pRasterIO= NULL;


//Use Load to load an image
void __fastcall TForm1::Button1Click(TObject *Sender)
{
   CoCreateInstance(CLSID_LEADRasterIO, NULL, CLSCTX_ALL, IID_ILEADRasterIO, (void**)&pRasterIO);
   LEADEventSink1->Connect (pRasterIO, DIID__LEADRasterIOEvents);
   pRasterIO->Load (LEADRasterView1->Raster, AnsiToOLESTR("v:\\images\\24bit.bmp"), 0, 1, 1);
}

void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
{
   if(pRasterIO)
      pRasterIO->Release();
}
void __fastcall TForm1:: LEADEventSink1Invoke(TObject *Sender, int DispID,
      const TGUID &IID, int LocaleID, WORD Flags, tagDISPPARAMS &Params,
      Pointer varResult, Pointer ExcepInfo, Pointer ArgErr)
{
   switch (DispID)
   {
        case LEADRASTERIOEVENTS_FILEPAGE:
      {
         float HeightFactor, WidthFactor;  // Factors for aspect ratio
         float HeightAllowed, WidthAllowed;   // Maximum width and height

         // Set the variables used for preserving the aspect ratio.
         //Allow for a border of 1/8 of the form size.
         //The units of measure do not matter, since we are calculating proportions.
         HeightFactor= pRasterIO->InfoHeight;
         WidthFactor= pRasterIO->InfoWidth;
         HeightAllowed= ClientHeight * 3 / 4;
         WidthAllowed= ClientWidth * 3 / 4;
         //Center the LEAD RasterView control on the form, preserving the aspect ratio.
         //Check to see if using the maximum width will make the image too tall.
         //Set the dimensions based on the result.
         if (((WidthAllowed * HeightFactor) / WidthFactor) < HeightAllowed)
         {
            LEADRasterView1->Left= ClientWidth / 8;
              LEADRasterView1->Width= WidthAllowed;
              LEADRasterView1->Height= (LEADRasterView1->Width * HeightFactor) / WidthFactor;
              LEADRasterView1->Top= (ClientHeight - LEADRasterView1->Height) / 2;
         }
         else
         {
           LEADRasterView1->Top= ClientHeight / 8;
           LEADRasterView1->Height= HeightAllowed;
           LEADRasterView1->Width = (LEADRasterView1->Height * WidthFactor) / HeightFactor;
           LEADRasterView1->Left = (ClientWidth - LEADRasterView1->Width) / 2;
         }
         // Set the image display size to match the LEAD RasterView control.
         LEADRasterView1->AutoScroll = False;
         LEADRasterView1->AutoSetRects = True;
         LEADRasterView1->AutoRepaint = True;
         LEADRasterView1->PaintSizeMode = PAINTSIZEMODE_FIT;
      }
      break;
   }
}