1. Label
A label is a label used to display on the screen. The usage is as follows:
- Create a traditional project
- Define a CEikLable class in the. h file of the container.
Class CEikLable; defined by forward
- Add a class member variable CEikLable * iLabelTest;
- Add the include reference in the. cpp file of the container # include <eiklabel. h>
- Create the variable in the constructL method, as shown in the following code:
ILabelTest = new (ELeave) CEikLabel; iLabelTest-> setcontainer1_wl (* this);/* set the font for the label by referencing eikenv. h. Therefore, you can obtain the CEikonEnv pointer through * CEikonEnv: Static (), and then call * its member method to obtain a const CFont pointer. ** other methods: Reference aknutils. h. You can get the system-defined font. * search for aknutils to find the global font. */const CFont * aFont = CEikonEnv: Static ()-> AnnotationFont (); iLabelTest-> SetFont (aFont); iLabelTest-> SetTextL (_ L ("label test"); iLabelTest-> SetUnderlining (ETrue); ILabelTest-> SetAlignment (EHRightVTop ); |
The font is used here. You need to add the header file:
# Include <eikenv. h> # include <gdi. h> # include <aknutils. h>
# Include <gulalign. h>
And corresponding library files
Gdi. lib
- In SetExtent is required for CEikLable in the SizeChanged method.
ILabelTest-> SetExtent (TPoint (50, 50), iLabelTest-> MinimumSize ());
If you try to remove this label, the label cannot be displayed. This label is used to set the position and size of the display.
- CountComponentControls () and ComponentControl (TInt aIndex)
Is used to return the total number of components in the container and the number
Run the following code:
// Counter // CsimplecontrolContainer: CountComponentControls () const // counter // TInt CsimplecontrolContainer: CountComponentControls () const {return 5; // return nbr of controls inside this container} // CsimplecontrolContainer: ComponentControl (TInt aIndex) const // component // CCoeControl * CsimplecontrolContainer: ComponentControl (TInt aIndex) const {switch (aIndex) {case 0: return iLabel; case 1: return iToDoLabel; case 2: return iLabelTest; case 3: return iDateEditor; case 4:// This is written as 5 during debugging, and the result is always incorrect because it takes a long time to locate the cause.Return iEdwin; default: return NULL ;}} //--------------------------------------------------------- |
- Compile and run the program to see the effect.
2. Edit the input control
When the exercise editing input control is used, CEikDateEditor is used.
The required header file is: # include <eikmfne. h>
The LIB library file is eikctl. lib.
RSS file definition:
RESOURCE DATE_EDITOR r_my_date_edit {minDate = DATE {year = 1900 ;}; maxDate = DATE {year = 2100 ;}; } |
The difference between creating a CEikDateEditor and a lable is that lable is not put in rss, while CEikDateEdit is put in Rss,
The code for creating CEikDateEditor is as follows:
TResourceReader read; iCoeEnv-> convert (read, R_MY_DATE_EDIT); iDateEditor = new (ELeave) CEikDateEditor; iDateEditor-> setcontainer1_wl (* this); iDateEditor-> ConstructFromResourceL (read ); CleanupStack: PopAndDestroy (); |
TResourceReader is used in the Code. This class must reference the header file: barsread. h and the library file: bafl. lib.
For general input controls CEikEdwin and CEikDateEditor, except for the rss definition, the definition and creation of other controls are the same.