Introduction to Applications |
|
Windows Fundamentals |
Introduction to the Win32 Library |
|
A library is a set of published documents. It could consist of a piece of paper, a book, or a group of books used as a (written) reference for a specific purpose. The programs that are on a Microsoft Windows operating system follow a set of rules and suggestions defined in a library called Win32 (Windows 32-bits). |
Win32 is a group of files, functions, objects, resources, data types, and constants that define how the Microsoft Windows family of operating systems function. As a reference, it allows individuals and companies to know what is necessary in order to create or develop applications for this specific platform. Over all, it is not strictly necessary to know Win32 thoroughly to write programs; but it is highly recommended to know as much as possible about Win32 to be an effective Windows programmer. |
In order to create a Win32 application in C++Builder, on the main menu, you can click File -> New -> Other... In the left list of the New Items dialog box, click, you can click C++Builder Projects. On the right list, click Console Application and click OK. From the New Console Application dialog box, click the C++ radio button and make sure the Console Application check box is unchecked.
As you may know already, you will use your knowledge of C++ to develop C++Builder applications. This includes the ability to create objects, declare variables, create classes, use your own classes, use or use classes created by other people, etc. Most of the classes you will use have already been created. Still, in some cases, you will want to create your own classes. You can separately create a header file and a source file or create a unit that becomes a class. To create any of these, use the New Items dialog box. In the left list, click C++Builder Files. In the right list, make your choice and click OK. To manage classes, you can use the Class Explorer. To get it, on the main menu, you can click View -> C++ Class Explorer.
As every C++ application specifies the main() function as its entry point, every Windows application must have a function called WinMain. If you want to support Unicode (namely long strings) in your application, use _tWinMain. If you start a Win32 application using the New Console Application, C++Builder would display syntax of the _tWinMain() function. This is: WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow); If you start a default graphical application, a source file with the name of the project would be created and it would have this syntax of the _tWinMain() function.
To make application development easier, that is, to provide Rapid Application Development (RAD), the Visual Component Library (VCL) is equipped with various classes. The most fundamental class is named TObject.
This is the ancestor to all VCL classes you will use in an application. The TObject class is defined in the System.hpp header file. As the parent of all VCL classes, it gives some common functionalities to its children, including:
You will hardly, if ever, need to declare a variable of type TObject. Instead, if necessary, you can create a class that derives from TObject. The TObject class is equipped with many methods and no properties.
Persistence is the ability to write or to read a value. The value can be written to an object. The object can be physical such as a hard drive or a DVD drive, or it an be virtual such as a variable. In the same way, the value can be read from the same type of object. These two operations make it possible to share values, such as to assign one object to another. To provide this functionality to objects, the VCL provides a class named TPersistent. The TPersistent class is defined in the Classes.hpp header class. The TPersistent class is derived from TObject:
TPersistent is the ancestor to all classes that use properties, so these properties can be written to or read from. The TPersistent class is equipped with a method named Assign. Its syntax is: virtual void __fastcall Assign(Classes::TPersistent * Source); This method makes it possible to assign an object to another another. You can either use this method or the assignment operator "=".
A component is an object that is used in a graphical application. Examples of components are buttons, pictures, check boxes, mouse cursor, or lists. The most fundamental aspect of a component is that it must be created. The most fundamental object of a computer is the operating system. It gives life to the computer and the objects that would appear on it. Most of these objects are seen on the screen. In fact, as far as a user is concerned, an application is a series of objects that can be seen and used. Some objects can carry other objects, which means they act as parents. An object A that holds or carries another object B is referred to as its owner. To support these various scenarios, the ability for a component to appear in an application and the ability for one component to own another component, the VCL provides a class named TComponent. The TComponent class is defined in the Classes.hpp header file. The TComponent class is derived from TPersistent:
TComponent is the ancestor for objects that appear in an application. The TComponent class is equipped with many properties and methods. As mentioned already, one of the characteristics of a component is that it can own other components. To give you access to the objects that a component owns, the TComponent class is equipped with a property named Components: __property Classes::TComponent * Components = {read=GetComponent}; The TComponent::Components property is a collection or array where each element is an object on the component. One of the properties of the TComponent class is named ComponentCount: __property int ComponentCount = {read=GetComponentCount}; TComponent::ComponentCount is a read-only property that produces the number of objects inside a component.
In a computer application, a control is an object that appears, or has a physical presence, on the screen. To make this possible, a control presents some visual characteristics such as borders or colors. A control can also exhibit a behavior, such as the ability to move or change. To support the concept of controls, the VCL provides a class named TControl. The TControl class is derived from TComponent:
The TControl class is defined in the Controls.hpp header. The TControl class is equipped with many properties and methods that we cannot review at this time.
A Windows control is an object that can react to a user. For example, it can receive key strokes (from the keyboard) or can respond when a mouse acts on it. Examples of Windows controls are buttons, list views, check boxes, menus, radio buttons, dialog boxes, or scroll bars. To support Windows controls, the VCL provides a class named TWinControl. The TWinControl class is derived from TControl:
The TWinControl class is defined in the Controls.hpp header. The TWinControl class is equipped with many properties and methods that we cannot review at this time. |
A computer application, also called an application, is a series of instructions that tell the computer what to do, when an how. These instructions are group in one entity named a project. In Microsoft Windows, to create an application, you use one of two structures named WNDCLASS and WNDCLASSEX. These two structures are defined respectively as follows:
For a Win32 application, you must declare a variable of one of these structures. Then you should provide, or at least control, the value of each of the member variables. To support applications, or to simplify the creation of an application, the VCL provides a class named TApplication. The TApplication class is derived from the TComponent class:
The TApplication class is defined in the Forms.hpp header file. TApplication is used to create, or get access to, an application. It is the main central point of an application as a Windows entity. To give you ample access to the application and to the screen, every GUI application you develop using the VCL declares a TApplication variable. This means that you will hardly, if ever, need to declare a variable of this class since it is already available to your application. To create an application, the TApplication class provides the Initialize() method. Its syntax is simply: void __fastcall Initialize(void); This creates an empty application without much to do. If you start an application such as Notepad, you are
said to have created an instance of the application. In the same way, when
you declare a variable of a class, an instance of the class is created and
made available to the project. In fact, when you create an application, you
must create an instance of that application so it can be made available to
the operating system. Once the instance exists, it can be accessed either by
any control of the same application or by the operating system. After creating an application, you can create an object that the user will look at when interacting with the computer. Such an object is called a window. Most of the things you see on the screen or on an application are window objects. As various as they are, there are different techniques used to create them.
The screen is the monitor that allows a person to visually interact with the machine. The screen includes such information as the computer’s desktop, its size, the display monitor, and other pieces of information related to a screen as an object or related to the objects of an application. To give you information about the screen that is being used in your application, the VCL provides the TScreen class. The TScreen class is derived from TComponent:
As mentioned for the TApplication class, when you create a VCL project a global TScreen variable is automatically declared so you will never need to explicitly create a TScreen object.
Rapid application programming (RAP) and rapid application development (RAD) consists of visually creating a computer programm by adding objects to the projects and writing code only when necessary. This makes the development go fast and allows the programmer to regularly preview the result. Although you can manually create a fully functional application in Embarcadero RAD Studio, the goal of using it is to take advantage of its rich design interface and objects. For this reason, for the rest of our lessons, we will use RAD as much as possible. There are many ways you can start a visual application in Embarcadero RAD Studio:
Any of these actions would create a new project display a starting form.
To open a project:
|
|
|||||||||||||||||||
|
|
||
Previous | Copyright © 2010-2016, FunctionX | Next |
|