001 – Creating a Windows application in C++ Builder

Example of creating a Windows application in C++ Builder

1. Creating the Application.

After starting for execution Borland C++ Builder we need to select the next command sequence (Figure 1).

File->New->VCL Forms Application - C++ Builder

05_01_00_001_01_

Fig. 1. Command to create a new application

 

2. The main form of application.

A new form will be created by automatically and a system’s window will be as shown in Figure 2.

05_01_00_001_02_

Fig. 2. The C++ Builder main window after Windows application creating

 

3. Project saving.

Before the beginning of the application development is recommended to save the project using next command sequence File->Save All (Fig. 3).

05_01_00_001_03_

Fig. 3. Project saving

Saving a project takes place in two steps. The first step is the saving of the main application form. By default the name Unit1.cpp is proposed.

The second step is the saving of project. By default, the system offers a file named Project1.cbproj (Fig. 5). After compiling based on a given project name will be formed executive module Project.exe.

05_01_00_001_04_

Рис. 4. Saving of main form’s file

05_01_00_001_05_

Рис. 5. Saving of project file

 

4. The files for the work with project.

After saving the file of the entire project and saving the main application form in the Borland C++ Builder system created the following main files.

4.1. The file of entire project, which has the extension “*.cbproj“. Project file contains the information described using tags of XML language. Information includes details about options of created project (project design modules and connected resources and other system options) that needed for assembling of executable file.

4.2. File Project1.cpp, which contains the function WinMain(), which is the entry point to the program.

4.3. Files Unit1.h, Unit1.cpp and Unit1.dfm which describe the basic form of the program.

File Unit1.h is the heading file for Unit1.cpp and contains a description of the main form class. New components, methods or variables to be added to the basic form of the program are described in the file Unit1.h.

Unit1.cpp file contains the implementation of classes, methods or variables described in the file Unit1.h. In fact, all code that refers to the basic form of the program is placed in this file. In most cases, the file contains an implementation of additional methods of form class , which can be, for example, event handlers components that are placed on the form.

Listing of the Unit1.dfm file is following:

object Form1: TForm1
  Left = 0
  Top = 0
  Caption = 'Form1'
  ClientHeight = 206
  ClientWidth = 455
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
end

As you can see, the Unit1.dfm file contains a description of the properties forms that affect its appearance and behavior.

4.4. The “Project1.res” file.

This file contains an application resources. The resources in application can be strings, images, text files and more.

 

5. Running the program.

To start an application simply select the command sequence

Run -> Run

or press the F9 button. Window of executable application is shown in Fig. 6. So far the application do not executes any useful work. But it responds to the system menu commands (minimize, maximize, close – Alt + F4). When you first run the application, in the folder with the application will be created a subfolder “bin“, which will be include the executive module of application (in this case Project1.exe).

Further, the programmer can place on the form some new components, can bind these components by events, can create any custom methods in the form, can describe own variables, etc.

05_01_00_001_06_

Fig 6. Program window after running


Related topics