Symbian basic class Summary

Source: Internet
Author: User
Tags character classes
Symbian basic class Summary

Class summary:
Four kings: caknapplication, ceikdocument, caknappui, and caknview

Void caknappui: dyninitmenupanel (tint aresourceid, ceikmenupane * amenupane)

Called before the menu pane is displayed, it is mainly used to initialize the specific items displayed in the menu.

Aresourceid is the specific resource ID, such as r_sms_menu.

Amenupane displays or hides this menu option by calling amenupane-> setitemdimmed (menu item resource ID, efalse. Note: etrue is hidden.

1. Dialog Box: ceikdialog (OK/cancel)
The main member functions are:

Void prelayoutdyninitl (); // process the initialization action before the dialog box appears

Tbool oktoexitl (tint abuttonid); // process the OK statement

Void handlecontrolstatechangl (tint acontrolid); // control changes in the listener dialog box, a bit similar to void caknappui: handlecommandl (tint acommand) of the Appui class ).

// Construction method:

Cmmssenddialog * isenddialog = new (eleave) cmsssenddialog;

Isenddialog-> setmopparent (this );

Isenddialog-> executeld (r_mmssend_dialog );

// --------------------------------- Define a dialog box resource ---------------------------

Resource dialog r_mmssend_dialog

{

Flags = eeikdialogflagnodrag | // unable to drag

Eeikdialogflagnotitlebar | // No title bar

Eeikdialogflagfillappclientrect | // applyProgramCustomer zone Filling

Eeikdialogflagcbabuttons | // use the CBA button

Eeikdialogflagmodeless; // button events not accepted

// For more information, see SDK: Developer Library? API reference? C ++ api reference? Uiklafgt

Buttons = r_avkon_softkeys_options_exit;

Form = r_mmssend_form;

}

//---------------------------------------------------------

// Default single row Display Mode


//---------------------------------------------------------

// It can be set to double.

Resource form r_mmssend_form

{

Flags = eeikformeditmodeonly |

Eeikformusedoublespacedformat;

// Specify a style of form optionally. The default setting is single line display.
// 1. eeikformusedoublespacedformat: double line display.
// 2. eeikformhideemptyfields: to make empty data fields invisible.
// 3. eeikformshowbitmaps: to display a bitmap on a label.
// 4. eeikformeditmodeonly: to display the form in edit mode only.

Items =

{

Dlg_line

{

Type = eeikctedwin; // It is an editing text box editor window

// In fact, this is an enumeration type. See the SDK:

// Developer Library? API reference? C ++ api reference? Uiklafgt? Uiklafgt resource constants? Teikstockcontrols

Prompt = qtn_mmssend_recipient_prompt; // string displayed by the label of this control

Id = emmsrecipienteditor;

Control = Edwin

{

Flags = eeikedwinnohorizscrolling | eeikedwinresizable;

Width = qtn_mmssend_recipient_width;

Maxlength = qtn_mmssend_recipient_maxlenght;

Default_input_mode = eakneditornumericinputmode; // digital input mode

};
},

Dlg_line

{

Type = eeikctedwin;

Prompt = qtn_mmssend_subject_prompt;

Id = emmssubjecteditor;

Control = Edwin

{

Flags = eeikedwinnohorizscrolling | eeikedwinresizable;

Width = qtn_mmssend_subject_width;

Maxlength = qtn_mmssend_subject_maxlenght;

Default_input_mode = eakneditortextinputmode; // text input mode

};
}
};

}

2. cycle type:
1. cperiodic
========================================================== ======================================

Cperiodic * iperiodictimer;

Iperiodictimer = cperiodic: newl (cactive: eprioritystandard); // This statement is generally in constructl ()

Void cgraphicsappview: starttimer () // start the clock

{

If (! Iperiodictimer-> isactive ())

{Iperiodictimer-> Start (1, 1,

Tcallback (cgraphicsappview: period, this); // tcallback is a method callback function. In terms of usage, it can only callback static methods in the class.

}

}

Tint cgraphicsappview: Period (Tany * aptr) // periodic start function. Note that this is a static function, but static is only stated in the header file.

{

(Static_cast <cgraphicsappview *> (aptr)-> doperiodtask ();

Return etrue;

}

Void cgraphicsappview: doperiodtask () // what the real cycle is doing

{

// Update the screen

Cwindowgc & GC = systemgc ();

GC. Activate (* drawablewindow (); // clear the screen if required. Add GC. Clear ();

Updatedisplay (); // This function is a periodic implementation.

GC. Deactivate ();

}

Void cgraphicsappview: stoptiem () // stop the clock

{

If (iperiodictimer-> isactive ())

{

Iperiodictimer-> cancel ();

}

}

2. rtimer
Rtimer timer;

Trequeststatus timerstatus; //... its associated Request status

Timer. createlocal (); // always created for this thread.

For (tint I = 0; I <10; I ++)

{// Issue and wait for single request

Timer. After (timerstatus, 1000000); // sets the clock request to 1 second.

User: waitforrequest (timerstatus); // wait for this request

// Display the tick count

_ Partition (kformat3, "tick % d \ n ");

Console-> printf (kformat3, I );

}

3. tTime
TTime time; // time in microseconds since 0ad nominal Gregorian

_ Partition (ktxt2, "The time now is ,");

Console-> printf (ktxt2 );

Time. hometime (); // set the time to the current system time

Showtime (time); // display the current time

// ---------------- The followingCodeManually add 10 seconds to the time --------------

Ttimeintervalseconds timeintervalseconds (10 );

Time + = timeintervalseconds;

Showtime (time); // print the time the request shocould complete

//---------------------------------------------------------

Timer. At (timerstatus, time); // set the clock request to 10 seconds.

User: waitforrequest (timerstatus); // wait for this request

// Say it's over, and set and print the time again

_ Timeout (ktxt4, "your 10 seconds are up \ nthe time now is ,");

Console-> printf (ktxt4 );

Time. hometime (); // set time to now

Showtime (time); // print the time

// Close Timer

Timer. Close (); // close Timer

3. string type:
Tdesc is the ancestor of all character classes

Standard C Language
Symbian OS

Let a string enter the binary code
Static char hellorom [] = "Hello"
_ Bytes (khellorom, "hello ")

Obtain the string pointer in the stack
Const char * helloptr = hellorom
Tptrc helloptr = khellorom

Get the pointer of the string in the stack
Char hellostack [sizeof (hellorom)];

Strcpy (hellostack, hellorom );
Tbufc <5> hellostack = khellorom;

Get the pointer of the string in the heap
Char * helloheap =

(Char *) malloc (sizeof (hellorom ));

Strcpy (helloheap, hellorom );
Hbufc * helloheap =

Khellorom. alloclc ();

A) tptrc is equivalent to a constant String constant.

B) tptr is equivalent to string type. Tbuf is equivalent to Char []. The only difference between the former and the latter is that the latter needs to specify the size of the allocated stack space.

C) hbufc * is similar to char. Allocated space on the stack.

Hbufc * textresource;

// Two string value attaching Methods

Textresource = stringloader: loadlc (r_hewp_time_format_error );

Textresource = ieikonenv-> allocreadresourcel (r_example_text_hello );

Tbuf <32> timeastext;

Timeastext = * textresource;

/* Data type conversion */

Tbuf to tptrc16
Tbuf <32> ttext (_ L ("05:44:00 "));
Tptrc16 tptrsecond = ttext. mid (17,2 );

Tptrc16 to tbufc16
Tptrc16 tptrsecond = ttext. mid (17,2 );
Tbufc16 <10> bufcs (tptrsecond );

Tbufc16 to tptr16
Tbufc16 <10> bufcs (tptrsecond );
Tptr16 F = bufcs. Des ();

Tptr16 to tbuf
Tbuf <10> bufsecond;
Bufsecond. Copy (f );

Tbuf to tptr16
Tbuf <10> bufsecond (_ L ("ABC "));
Tptr16 F;
F. Copy (bufsecond );

Tbuf to tint
Tint Asecond;
Tlex ilexs (bufsecond );
Ilexs. Val (Asecond );

Tint to tbuf
Tbuf <32> tbuf;
Tint I = 200;
Tbuf. Num (I );

1. String Conversion to numbers
Tbuf16 <20> Buf (_ L ("123 "));
Tlex Lex (BUF );
Tint inum;
Lex. Val (inum );
2. convert numbers into strings
Tbuf16 <20> Buf;
Tint inum = 20;
Buf. Format (_ L ("% d"), inum );
3. convert a Symbian string to a char string
Char * P = NULL;
Tbuf8 <20> Buf (_ L ("AAAAA "));
P = (char *) BUF. PTR ();

4. UTF-8 to Unicode
Cnvutfconverter: converttounicodefromutf8 (ibuf16, ibuf8 );
5. Unicode conversion to UTF-8
Cnvutfconverter: convertfromunicodetoutf8 (ibuf8, ibuf16 );

6. convert a char string to a Symbian string
Char * Cc = "aaaa ";
Tptrc8;
A. Set (const tuint8 *) CC, strlen (CC ));

7. Convert tptrc8 to tptrc16

// Get a ibuf8 from a ibuf16 (data are not modified)
Tptrc8 ptr8 (reinterpret_cast <const tuint8 *> (ibuf16.ptr (), (ibuf16.size () * 2 ));
Ibuf8 = ptr8;

// Get a ibuf16 from a ibuf8 (data are not modified)
Tptrc16 ptr16 (reinterpret_cast <const tuint16 *> (ibuf8.ptr (), (ibuf8.size ()/2 ));
Ibuf16 = ptr16;

The second one takes each character and convert it to the other format. The 16-bit to 8-bit conversion may not always succeed in this case:

Code:

// Get a ibuf8 from a ibuf16 (data are modified)
Cnvutfconverter: convertfromunicodetoutf8 (ibuf8, ibuf16 );

// Get a ibuf16 from a ibuf8 (data are modified)
Cnvutfconverter: converttounicodefromutf8 (ibuf16, ibuf8 );

This second method requires to include the UTF. h header and to link against charconv. Lib.

/* Memset memcpy strcpy */

The main application of memset is to initialize a memory space. It is used to set all the memory space to a certain character.
Memcpy is used to copy data from the source space to the target space. It is used for memory copying to copy any data type objects.
Strcpy can only copy strings. It ends copying when '\ 0' is encountered.

Strcpy
Prototype: extern char * strcpy (char * DEST, char * SRC );
Usage: # include <string. h>
Function: Copies the string ending with null indicated by Src to the array indicated by DeST.
Note: The memory areas specified by Src and DEST cannot overlap and DEST must have sufficient space to accommodate SRC strings.
Returns the pointer to DeST.

Memcpy
Prototype: extern void * memcpy (void * DEST, void * SRC, unsigned int count );
Usage: # include <string. h>
Function: copy count bytes from the memory area indicated by Src to the memory area indicated by DeST.
Note: the memory areas specified by Src and DEST cannot overlap. The function returns a pointer to DeST.

Memset
Prototype: extern void * memset (void * buffer, int C, int count );
Usage: # include <string. h>
Function: sets the first count byte of the memory area referred to by buffer to character C.
Note: The pointer to the buffer is returned.

4. File and stream operations
Location: s32file. h

The file simulation path is under c: \ Symbian \ 8.0a \ epoc32 \ wins. There are two partitions: C and D.

Rfs fs;
User: leaveiferror (FS. Connect ());
Rfile File
User: leaveiferror (file. Open (FS, _ L ("C: \ file. foo"), efilewrite ));
Tbuf8 <256> Buf;
File. Read (BUF, 256 );
File. Seek (eseekstart, 911 );
File. Write (_ L8 ("some thing you wanna write ..."));
File. Close ();
1) establish communication with the file server:

RFS fssession;

Tint fsret = fssession. Connect (); // start a file session

If (fsret! = Kerrnone)

{Console-> printf (ktxtconnectfailed, fsret );

User: Leave (fsret );

}

2) check whether the file path exists.

Fssession. mkdirall (kfullnameoffilestore); // make sure directory exists

3) create a file storage

Tparse filestorename; // The class uses the full filename structure supported by Symbian

Fssession. parse (aname, filestorename );

/* Configure /*------------------------------------------------------------------------------------------------

Tdesc & aname. Assign a value to the aname using the following method:
_ Partition (aname, "C :\\ epoc32ex \ data \ simpleclasstosimplestream. dat ");

Optional ----------------------------------------------------------------------------------------------*/

// Construct file store object-the file to contain

// The store replaces any existing file of the same name.

Cfilestore * // If efileread is a read stream

Store = cdirectfilestore: replacelc (fssession, filestorename. fullname (), efilewrite );

Store-> settypel (kdirectfilestorelayoutuid); // you can specify a storage type.

4) Write external data into the stream: (memory mode:> point to data flow) // suppose: tsimple anxxx;

Rstorewritestream outstream;

Tstreamid id = outstream. createlc (* store );

// ---------------------------- Write a scalar to the data stream ------------------

Outstream <anxxx;

Or astream. writeint8l (anxxx );

In fact, stream extension is used here: (this extension is used when the output is not common metadata) This is a overload of virtual functions.

Void tsimple: externalizel (rwritestream & astream) const

{

Astream <itheenum;

Astream <ibuffer;

Astream. writeint32l (iintvalue );

Astream. writeuint32l (iuintvalue );

Astream. writereal64l (irealvalue );

}

// Configure //------------------------------------------------------------------------------------------------

// Submit the stream changes to the file server.

Outstream. commitl ();

5) read the stream to external data:

Rstorereadstream instream;

Store-> setrootl (ID); // you can use the existing stream as the root of the stream. The advantage is that you no longer need to create a stream ID. In fact, memory is saved.

// Commit Changes to the store

Store-> commitl ();

// Construct and open the input stream object. We want to access the root stream from the store in this example.

Instream. openlc (* store, store-> root ());

Tsimple thesimple;

Instream> thesimple; // write Class Object Data.

//---------------------------------------------------------------------

Void tsimple: internalizel (rreadstream & astream)

{

Astream> itheenum;

Astream> ibuffer;

Iintvalue = astream. readint32l ();

Iuintvalue = astream. readuint32l ();

Irealvalue = astream. readreal64l ();

}

// ------------------------------ The output streams to other data elements or class objects ----------------------------

Anxxx = TXXX (astream. readint8l ());

6) disable file service communication

Fssession. Close ()

5. activity scheduling table
Because multi-thread processing of asynchronous requests consumes system resources, Symbian uses active objects to solve asynchronous requests.
The active sched is used to process asynchronous requests initiated by the active object. It detects the asynchronous requests made by the activity object and schedules the execution sequence of the event completion requests of the activity object. The activity scheduler uses only one event processing thread to plan the Event requests initiated by each activity object. Therefore, it consumes less resources than multi-threaded asynchronous requests.

1. Create an activity scheduler object and install it to the current thread.

Cactivescheduler * scheduler = new (eleave) cactivescheduler (); // create an activity Scheduler
Cleanupstack: pushl (schedhl );
Cactivesched: Install (sched); // install the scheduler.
Trapd (error, doinstancel (); // specific scheduled function processing.

You must start the scheduler in the specific scheduling function.

Cactivescheduler: Start (); // This statement tells the scheduler to wait for the state of the object to change.

2. Add yourself to the activity planner. Generally, This is a class. You can declare the following code in the class constructor.
Cactivescheduler: add (this );

// This class must have one inherited from public cactive, public mmsvsessionobserver

// When constructing a function, you can also declare the priority level: tclassa: classa (): cactive (0)

3. Return the change fact:

Setactive (); // The cactive Class Object submits an asynchronous request.

// This request indicates that the object has been changed. It will trigger cactive: runl ()

4. Here, cactivesched only manages one cactive object, that is, timecount. You can use a similar method to implement multiple cactive instances and add them to cactivescheduler, cactivescheduler will wait for changes in the status of all the cactive instances that are added to it. One of the changes will execute the corresponding processing function of the active object. When the status changes at the same time, the object priority is used to determine the runl function that is called first. cactivescheduler is also non-preemptible. When a runl function has not been executed, if the status of another cactive function changes, it will wait until runl is executed and then execute another cactive function.

6. Thread:
1. Create a waiting thread:

Tint res = kerrnone;

// Create server-if one of this name does not already exist

Tfindserver findcountserver (kcountservername );

Tfullname name;

If (findcountserver. Next (name )! = Kerrnone) // We don't exist already

{

Rthread thread;

Rsemaphore semaphore;

Semaphore. createlocal (0); // create a semaphore and wait until the thread ends normally.

Res = thread. Create (kcountservername, // create new server thread

Ccountservserver: threadfunction, // main function started by the thread

Kdefastackstacksize,

Kdefaultheapsize,

Kdefaultheapsize,

& Semaphore // The final parameter required by the main function is passed as Tany * argument to thread function

);

If (RES = kerrnone) // thread created OK-now start it going

{

Thread. setpriority (eprioritynormal );

Thread. Resume (); // start it going

Semaphore. Wait (); // wait until it's initialized

Thread. Close (); // we're no longer interested in the other thread

}

Else // thread not created OK

{

Thread. Close (); // Therefore we 've no further interest in it

}

Semaphore. Close ();

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.