1 / 13

C++ programming in Windows environment

Department of Information Engineering INFORMATION TECHNOLOGY dr. László Dudás 10./0. C++ programming in Windows environment. The Borland C++ Builder. Building elements of the program: the components. The Visual Component Library (VCL). Structure of VCL.

donalddixon
Télécharger la présentation

C++ programming in Windows environment

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Department of Information Engineering INFORMATION TECHNOLOGY dr. László Dudás 10./0. • C++ programming in Windows environment The Borland C++Builder • Building elements of the program: the components • The Visual Component Library (VCL) • Structure of VCL • Application models handling single, or multiple documents (SDI, MDI) • Project handling of C++ Builder • The first steps of making an application

  2. Department of Information Engineering INFORMATION TECHNOLOGY dr. László Dudás 10./1. • Building elements of the program: the components The component is such an object (e.g. a button) that works already during planning, writing the program, consequently the values of its properties can be set without writing program code. From a lot of pre-programmed components realising given task the exactly required instance can be selected for the program. The components can easily be put on the form of designed window selecting them from the component-palette.

  3. Department of Information Engineering INFORMATION TECHNOLOGY dr. László Dudás 10./2. The event is an occurrence, e.g. a button click by mouse, that comes from the user interaction or the Windows operating system. The list of events that can happen on a selected component (e.g. button) is given in the Events page of the Object Inspector. The handling of an event is performed by the event handler function of the component. The event handler is that among the member functions of the component affected by the event which starts to run because of the event and answers it (e.g. closes the window). The skeleton of the event handler function can be created in the program double clicking on the name of the selected event in the Events page. The internal code of the function that answers to the occurrence has to be written by us.

  4. The answering code has to be entered here by you! Department of Information Engineering INFORMATION TECHNOLOGY dr. László Dudás 10./3. Double click on the name of the event and the skeleton of the event handler is ready.

  5. Department of Information Engineering INFORMATION TECHNOLOGY dr. László Dudás 10./4. The components have non event handler member functions too, these functions are the methods. The methods can be called by us too in the code segment written by us. Among the methods there are the constructor and the destructor. E.g. the calling of the Focused() method answers the question is the control component in focus, so it is selected for getting the effects originate from the user actions. In the working program the control which is in the focus is set off using framing, colouring or another method. In case of Properties, Events and Methods the Help informs us about the ancestor class where these characteristics were defined the first time, where they are inherited to the class of theobject from.

  6. Department of Information Engineering INFORMATION TECHNOLOGY dr. László Dudás 10./5. The Help gives detailed information about properties of every single class. Because of its complexity the C++ Builder is practically not usable without the online Help. Program examples support the understanding and applying of components. A tutorial is included for beginners in the Help/C++ Builder Help/Contents/ Quick Start: Tutorials point. Example programs that introduce the possibilities of C++ Builder are in the Examples folder.

  7. Department of Information Engineering INFORMATION TECHNOLOGY dr. László Dudás 10./6. • The Visual Component Library (VCL) As C++ Builder is suitable for writing programs that run on Windows graphical operating system and use the resources of Windows API, it is evident that includes a graphical object library which uses and simultaneously hides the API. The visual attribute means that these objects mostly displayed on the screen: window-forms, menus, input panels, controls, etc. For non visual objects an example is the timer. VCL classes are organised into a class hierarchy. The C++ Builder borrowed this structure from the Borland Delphi program development environment, that uses the Object Pascal programming language. The VCL provides the components to a quick build-up of Windows-style user interface but the internal program code that gives the essence of the application has to be entered using C++ language. The capabilities of Object Pascal based VCL have the next differences comparedto possibilities of C++: • The VCL objects have to be created dynamically (new, delete) • The member functions of VCL objects have not default parameter values • The VCL objects cannot have multiple ancestors.

  8. Department of Information Engineering INFORMATION TECHNOLOGY dr. LászlóDudás 10./7. • Structure of VCL(detail) TObject TPersistent TStream TComponent TStrings TGraphic TApplication TControl TMenu TWinControl TGraphicControl TShape TImage TCustomControl TButtonControl TScrollingWinControl TCustomForm TButton TForm

  9. Department of Information Engineering INFORMATION TECHNOLOGY dr. László Dudás 10./8. TObject is the ancestor of VCL classes. The descendants of TPersistent class can save and load their features to/from files. TComponent is the ancestor of components. Their descendants have properties and methods that make possible to install them into the Component Palette and to add them to forms. TControl is the ancestor class of controls appearing in the user interface. The instances of TApplication class are the applications. It has methods like Initialize(); CreateForm(); Run(); for control of the application and to handle the message transmitting cycle. They are called in WinMain() function. TForm is class of windows, the main window of the application, the dialog windows of the user interface are derived from it. The structure, the parts of the built window are included in the .DFM file, the program code regarding its work is in the .CPP file and the declarations are given in the .H header file. The programmer don’t have to deal with the .DFM file, its creation is automatic. Custom classes can constitute the basis class of classes built further from them by the programmer. These new classes are not given in the class hierarchy originally.

  10. Department of Information Engineering INFORMATION TECHNOLOGY dr. László Dudás 10./9. • Application models handling single, or multiple documents (SDI, MDI) The applications can be of two sorts: The SDI, Single Document Interface program can use countless further dialog and message windows over the main window, but can work on one document only. The MDI, Multiple Document Interface program can run countless further document windows in the main window that have the same structure and can display different documents. The menus and icons in the main window refers to the active document. E.g. remember the Windows/Tile function of Excel. The application model of the main window of our application can be selected by the FormStyle property of its form. The document windows of an MDI application are non modal windows: more than one can be opened at the same time, every can be selected clicking in it and can be used for work. Such windows have to be displayed calling their Show() method. Modal windows have to be closed before clicking effectively inanother window of the application. Such windows applied in every application model: most of the dialog windows are such. This behaviour is caused by the ShowModal() method.

  11. Department of Information Engineering INFORMATION TECHNOLOGY dr. László Dudás 10./10. • Project handling of C++ Builder The C++ Builder development environment administers the files created during developing process hidden in the project file (e.g. football.bpr). The starting file including the WinMain() function is made automatically. (e.g. FOOTBALL.cpp).

  12. Department of Information Engineering INFORMATION TECHNOLOGY dr. László Dudás 10./11. The units consist of a .cpp and a .h pair of files. In case of forms this pair is completed with a .dfm form-definition file that is made automatically. The Project Manager does not show the .h header files. The .res resource file and other, rare used files (.txt, .bmp, .wav) can be attached to the above mentioned files.

  13. Department of Information Engineering INFORMATION TECHNOLOGY dr. László Dudás 10./12. • The first steps of making an application 1. Create a new folder which will store the files of the project. 2. Start C++ Builder. 3. If a previous project were open choose the File/Close all menu item and close it. Then create a new project with the File/New Application menu point. The C++ Builder creates the next files automatically: Project1.cpp : the main programUnit1.cpp : the source code file for the main form that is named unit fileUnit1.h : the header file for the main form that is named unit header file Unit1.dfm : resource file that describes the structure of the main form. 4. Choose the File/Save All menu item and save the files to the previously created folder. Rename the .bpr project file to taste during saving. The default names of units can be kept or renamed at will. 5. Later the full project has to be saved by the File/Save All menu item. This is expedient after every bigger modification.

More Related