AutoAnimate example for C++ Builder

This example gets information about an animated file, uses the information to position the LEAD control, and plays the animation as it loads the file.

void __fastcall TForm1::Button1Click(TObject *Sender)
{
   int HeightFactor,WidthFactor;
   int HeightAllowed,WidthAllowed;

   /*Force continued looping after the file loads. */
   Lead1->AutoAnimationLoop = AUTOANIMATIONLOOP_INFINITE;
   Lead1->GetFileInfo("d:\\ltwin11\\images\\eye.gif", 0);
   /*Exit if( this is not an animated file. */
   if( Lead1->InfoAnimation == False)
      ShowMessage("Not an animated file!!");
   else
   {
      /*Calculate information for centering the LEAD control. */
      /*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 = Lead1->InfoHeight;
      WidthFactor = Lead1->InfoWidth;
      HeightAllowed = ClientHeight * 3/4;
      WidthAllowed = ClientWidth * 3/4;
      /*Center the LEAD 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)
      {
         Lead1->Left = ClientWidth / 8;
         Lead1->Width = WidthAllowed;
         Lead1->Height = (Lead1->Width * HeightFactor) / WidthFactor;
         Lead1->Top = (ClientHeight - Lead1->Height) / 2;
      }
      else
      {
         Lead1->Top = ClientHeight / 8;
         Lead1->Height = HeightAllowed;
         Lead1->Width = (Lead1->Height * WidthFactor) / HeightFactor;
         Lead1->Left = (ClientWidth - Lead1->Width) / 2;
      }

      /*Set properties for playing the animation as is loads.*/
      Lead1->AutoAnimate = True;
      Lead1->AutoRepaint = True;
      /*Load the animated file.*/
      Lead1->Load("d:\\ltwin11\\images\\eye.gif", 0, 0, -1);
   }
}