Loading and Displaying an Image (C++ Builder 3.0)

Take the following steps to start a project and to add some code that positions, scales, and displays an image on the main form:

1. Start C++ Builder 3.0.

2. On the C++ Builder toolbar, click the ActiveX tab. If you have used a LEAD ActiveX control before, the icon appears on the toolbar. Otherwise, add the LEAD control as follows:

a. On the Component menu, choose Import ActiveX Control.

b. In the Import ActiveX dialog, highlight the LEAD Main Control (12). Change the Class name to TLEAD. Click Install.

c. If you have previously added a LEAD control, you will get a Confirm dialog that tells you that the xxx_TLB.cpp file already exists, and asks if you want to replace it. Click Yes.

d. In the Install dialog, click OK.

e. In the Confirm dialog, click Yes.

f. The Compiling Package DCLUSR35 dialog will appear. You may elect not to have this dialog appear again. Click Yes.

g. The Compiling dialog will appear.

f. After compiling has completed, the Information dialog will appear. Click OK.

g. At this point you will be presented with the DCLUSR35.cpp window, with USEUNIT and USERES lines for each LEAD control installed in the project. Save and close DLCUSR35.bpk. Do not save Unit1.cpp, Project1 or ProjectGroup1.

3. In the File menu, choose New Application.

4. Select the LEAD control on the ActiveX toolbar. Size and position the control as you want it to appear at run time, and change the name of the control to LEAD1.

5. Add a command button to your form and name it as follows:

Name

Caption

LoadLead

Load Image

6. Code the main form's FormShow procedure as follows. In online help, you can copy the block of code and paste it into your application.

void __fastcall TForm1::FormShow(TObject *Sender)
{
  /* Set defaults for displaying the image. */
  /*These are all persistent properties that can be set in the properties box. */
  LEAD1->Appearance = APPEARANCE_FLAT;
  LEAD1->BorderStyle = 1;
  LEAD1->BackColor = clYellow;
  LEAD1->PaintDither = PAINTDITHER_DIFFUSION;
  LEAD1->PaintPalette = PAINTPALETTE_AUTO;
  LEAD1->AutoRepaint = True;
  LEAD1->AutoSize = False;
  LEAD1->AutoSetRects = True;
  LEAD1->PaintSizeMode = PAINTSIZEMODE_FIT;
}

7. Code the LoadLead button's click procedure as follows:

void __fastcall TForm1::LoadLeadClick(TObject *Sender)
{
LEAD1->Load(StringToOleStr("e:\\LTWIN12x\\images\\image1.cmp"), 0, 0, 1);

}

8. Run your program to test it.

9. Save the project to use as a starting point for other tasks in this tutorial.