1 / 15

C++ Programming in Windows Environment: Visual Components and Their Properties

Learn about C++ programming in a Windows environment, focusing on the usage and properties of visual components. Explore common methods and event handler functions of visual components, as well as important properties of Forms.

jalfaro
Télécharger la présentation

C++ Programming in Windows Environment: Visual Components and Their Properties

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 11./0. • C++ programming in Windows environment Usage of visual components, resources • Common properties of visual components • Common methods of visual components • Common event handler functions of visual components • Main properties of Forms • Properties that can be used from programs only • Important specific methods of Forms • Main events in the life of a Form

  2. Department of Information Engineering INFORMATION TECHNOLOGY dr. László Dudás 11./1. • Common properties of visual components Visual components are used to build the user interface of our program. The components are placed on Form-components, rarely on top of other components inside a Form. The properties of components can be set during design time in the Object Inspector or in runtime assigning value to them. This latter method can be applied for data members that do not appear on Properties page of Object Inspector. Actions can be accomplished on component or interrogations may be done on its state calling its methods in the program. Event handler functions that are important for our program can be chosen and filled up with answering program code from the events that can be handled by the component.

  3. Department of Information Engineering INFORMATION TECHNOLOGY dr. László Dudás 11./2. Name propertyEvery component automatically gets a unique name that includes the name of the class and a serial number (e.g. Button1). This name will be used in the names of event handler functions of the object. These automatically generated names can be changed by us and the C++ Builder will modify every name occurrences in the code that was written by itself. This name modification has to be accomplished in the Object Inspector immediately after creation of the instance of component because the Builder does not actualise the code written by us. It is prohibited (though possible) to modify the code generated by the Builder. The new name will be shown as the Caption of the object, too. If this value of Caption is not suitable can be overwritten freely. Owner and Parent properties The Owner of the component is that object which is responsible for deleting it from the memory when the component becomes unnecessary. The Parent is that object which directly includes the component. E.g. if there is a button in a panel in a window then the Owner of the button is the window and the Parent is the panel.

  4. Department of Information Engineering INFORMATION TECHNOLOGY dr. László Dudás 11./3. Left and Top propertiesThey determine the place of the visual component ont the carrier Form or Panel giving the relative co-ordinates of the left top corner of the visual component. Their value can be negative too and may also be set from program. Width and Height propertiesThey determine the size of component. Minimum and maximum limits can given as defaults for certain components (e.g. Form). Hint propertyThe Hint, a small popup window appears when the mouse cursor stays a little longer on the visual component. This text gives a short description on component. The hint property can include two strings: a short ToolTip and an optional longer message, they have to be separated by a | character. The ToolTip appears in the yellow popup window while the longer hint may be shown in the status bar in the bottom of the window. They will be visible if the ShowHint properties are set to true in the Application object and for the component too.

  5. Department of Information Engineering INFORMATION TECHNOLOGY dr. László Dudás 11./4. Cursor propertyTo change the default cursor shape. The mouse cursor will change to this shape when is moved above the component. Instead of modifying the cursor property in the Object Browser modification from the program in runtime is usual. Enabled property The components may be insensible temporarily. This effect caused by the Enabled = false value. Such component can not be selected, the focus moved with Tab key steps over it. This state of it is indicated by visual distinction, e.g. pale appearance. Most of the components can take this state in runtime only, not at planning. The setting is made from program usually. Font property The format of caption or text of component can be set in wide range selecting the Font property then clicking on the button appearing on the right hand side to open the well-known character format dialog window.

  6. Department of Information Engineering INFORMATION TECHNOLOGY dr. László Dudás 11./5. Color property It serves for setting the colour of background of the component and the colour of characters. It is important to emphasize that beside the colour palette making possible setting any colour the default colour schemes are very important too to produce uniform appearance of our program and to make possible customization of system colours. E.g. instead of colour clWhite the colour clMenu can be selected. The clMenu is the colour of the operating system for menus. Use of these colour constants is practical. (See previous page.) HelpContext propertyFor giving the index of help text connected to the component. Tag propertyAn integer number can be connected to the component that can be used for identification of it in the program. Visible propertyIf true, the component is visible, if false then it is not visible and it is not enabled. Mostly it is set from the program.

  7. Department of Information Engineering INFORMATION TECHNOLOGY dr. László Dudás 11./6. • Common methods of visual components • Hide( ) method Hides the component and sets the Visible property to false. • Invalidate( ) methodA not urgent asking for repainting the component. The Windows repaints the component when finds time for it. • Refresh( ) methodAsking for clearing and immediately repainting. • Repaint( ) methodImmediately repainting of component without previous clearing. • SetFocus( ) methodSets the focus to the component and makes it active.

  8. Department of Information Engineering INFORMATION TECHNOLOGY dr. László Dudás 11./7. • Common event handler functions of visual components OnChange( ) event handler This function called when the component is changed. OnClick( ) event handlerThis function called when a mouse click happened on the component. OnDblClick( ) event handler A double click on the component calls this function. OnEnter( ) event handlerThis function is called when the component gets the focus, so it is selected. OnExit( ) event handlerThis function is called when the focus moves further from the component. OnPaint( ) event handlerThis function is called after repainting the component to make possible to perform additional drawing instructions.

  9. Department of Information Engineering INFORMATION TECHNOLOGY dr. László Dudás 11./8. • Common event handler functions of visual components, continuation • OnKeyDown( ) event handlerThis function is called if the component is in focus and one of the keys is pushed. • OnKeyPress( )event handlerThis function is called if an alphanumerical key or one of the Enter, Tab, Backspace or Esc keys was pressed. • OnKeyUp( )event handler Is called if a pushd key is released. • OnMouseDown( )event handlerIs called if the mouse cursor is above the component and one of the mouse button is pushed. Gives back the mouse co-ordinates, the pushed mouse button and the pushed altering keys (Alt, Ctrl or Shift). • OnMouseMove( )event handlerIs called when the mouse cursor moves above the component. • OnMouseUp( )event handlerIs called when the pushed button of the mouse is released while the mouse cursor is above the component.

  10. Department of Information Engineering INFORMATION TECHNOLOGY dr. László Dudás 11./9. • Main properties of Forms ActiveControlpropertyOne of thecontrols that are in the Form can be selected. This control will be active, will have the focus when the window becomes active. AutoScroll, horizontal and vertical scroll bars Settings of these properties control the scrolling of the window content if not every control that are in the window can be seen because the window has small size. (HorzScrollBar, VertScrollBar) BorderIcons propertyMakes possible to give the icons that can be seen in the upper right corner. BorderStyle propertyThe style may be sizeable (bsSizeable) or not sizeable (e.g. bsDialog , bsNone). FormStyle propertyUsually fsNormal. Sometimes can be: fsStayOnTop.For MDI Form: fsMDIForm and for its document: fsMDIChild.

  11. Department of Information Engineering INFORMATION TECHNOLOGY dr. László Dudás 11./10. ClientHeight and ClientWidth properties They give the size of the useable area of the Form without borders, title bar and scroll bars, having effect on properties With and Height. Icon propertyGives the application icon for the left side of title bar, this can be seen on Taskbar at minimisation of application too. Sometimes it is missing, if, e.g. the FormStyle = fsDialog. Position property Determines the position and size of Format the first appearance.Decided by Windows:poDefault. In design position: poDesigned. Every appearance in the center; of screen: poDesktopCen-ter, of main window: poMainFormCenter, of the owner Form: poOwnerFormCenter, of the selected screen of a multi-monitor application: poScreenCenter. WindowState property Opened to maximum size, normal, or minimized to icon.

  12. Department of Information Engineering INFORMATION TECHNOLOGY dr. László Dudás 11./11. • Properties that can be used from programs only These properties can not be set in design time, they are not shown in Object Inspector. ModalResult property: closing method of a Modal window.If ModalResult has been set for a button then pushing it results closing the dialog window. After closing the dialog window this value will be passed to it and presented as the returned value of the ShowModal() function of its owner window that gets back the execution. The closing pushing the button does not need handling an OnClick event. E.g.: closing the dialog window pushing the OK button the ModalResult of the ShowModal() function in the owner window will be mrYes, pushing No ModalResult will be mrNo, pushing Cancel will be mrCancel. If the previously set ModalResult is mrNone for the dialog window the closing will not accomplished. There are other properties that can be used from program only.

  13. Department of Information Engineering INFORMATION TECHNOLOGY dr. László Dudás 11./12. • Important specific methods of Forms BringToFront( ) methodCalling this member function the window represented by the Form will be displayed in front of all other windows. Close( ) method Its calling closes the window. (The closing can be avoided using the OnCloseQuery() event handler.) SetFocus( ) method Activises and brings to front the window.The control on the form selected by the ActiveControl property becomes active too. (Gets the focus.) Show( ) and ShowModal( ) methodsEvery form has to be created in the memory first. This may be performed defining a TForm type variable, a window-instance. After creation the window exists but is not visible. To display it calling of Show() or ShowModal() methods required. It is possible to click out from the non modal window to the other part of the application, from a modal window it is impossible, it has to be closed first.

  14. Department of Information Engineering INFORMATION TECHNOLOGY dr. László Dudás 11./13. • Main events in the life of a Form The constructor runs. The Form comes into beeing in the memory. OnCreate() The event handler of Form creation runs. ... Show() method-call for displaying the Form on the screen. OnShow() Event handler of form-displaying runs. OnActivate() Event handler of form activation runs. OnPaint() Event handler of form-drawing runs.…OnResize() If the window size changed the event handler runs. Repaint() method-call for redraw the Form on the screen because of resizing.OnPaint() Event handler of form-drawing runs. …OnMouseDown(); OnMouseMove(); OnMouseUp() Mouse event handlers.… Close() method-call to close the form, calls the CloseQuery() method. OnCloseQuery() A decision can be made in it if the window has to be closed. OnClose() Instructions performed at closing can be given in this handler. OnDestroy() The handler of the ‘window deleted from memory’ event runs. If there is destructor, then runs.

  15. Department of Information Engineering INFORMATION TECHNOLOGY dr. László Dudás 11./14. Remarks: If initialisations are required at form creation then use one ofthe constructor or OnCreate() event handler. Do not use both! Similarly use one of the OnDestroy() event handler or destructor to accomplish tasks that are required before deleting the form from the memory. The OnResize() event hadler runs when the size of the window was changed. The elements of the window can be repositioned, the included drawings can be redrawn, the texts can be rewrited in the required length, etc. in this event handler. These activities all require the redrawing of window calling the Repaint() method. From the event handlers those called by Windows run with default functionality if the programmer does not modify their content. Event handlers reacting to user interactions (e.g. mouse event handlers) are inserted into the program and programmed as necessary.

More Related