symbian基本类总结

类总结:

四大天王:CaknApplication,CeikDocument,CAknAppUi,CAknView

void CAknAppUi::DynInitMenuPaneL( TInt aResourceId, CEikMenuPane* aMenuPane )

在显示menu pane之前调用,主要是用来初始化菜单显示的具体项目。

aResourceId 是资源的具体ID,如R_SMS_MENU。

aMenuPane 通过调用aMenuPane->SetItemDimmed(菜单项目资源ID,EFalse);来显示或隐藏该菜单选项。注意:Etrue为隐藏。

1、话框类:CEikDialog   OK/CANCEL

主要成员函数有:

void PreLayoutDynInitL();//处理在对话框出现之前的初始化动作

TBool OkToExitL( TInt aButtonId );//对OK按的处理

Void HandleControlStateChangL(Tint aControlId);//监听对话框上控件改动,有点类似与Appui类的void CAknAppUi::HandleCommandL(TInt aCommand)

//构造方式:

    CMmssSendDialog* iSendDialog = new ( ELeave ) CMmssSendDialog;

       iSendDialog->SetMopParent( this );

    iSendDialog->ExecuteLD( R_MMSSEND_DIALOG );

//-------------------------------定义一个对话框资源---------------------------

 

RESOURCE DIALOG r_mmssend_dialog

    {

    flags =   EEikDialogFlagNoDrag |    // 无法拖曳

                       EEikDialogFlagNoTitleBar |  //无标题栏

                       EEikDialogFlagFillAppClientRect | //将应用程序客户区填满

                       EEikDialogFlagCbaButtons |  //使用CBA按钮

EEikDialogFlagModeless;   //不接受按钮事件

//以上可以参见SDK  Developer Library » API Reference » C++ API reference » UIKLAFGT

    buttons = R_AVKON_SOFTKEYS_OPTIONS_EXIT;

    form = r_mmssend_form;

    }

 

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

//默认的单行显示模式

  

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

//可以设置为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;    //是一个编辑文本框 Editor window

//实际上这个是枚举类型,可参看SDK

//Developer Library » API Reference » C++ API reference » UIKLAFGT » UIKLAFGT Resource Constants » TEikStockControls

    prompt = qtn_mmssend_recipient_prompt;// 这个控件的label显示的字符串

            id = EMmsRecipientEditor;

            control = EDWIN

                {

                flags = EEikEdwinNoHorizScrolling | EEikEdwinResizable;

                width = qtn_mmssend_recipient_width;

                maxlength = qtn_mmssend_recipient_maxlenght;

                default_input_mode = EAknEditorNumericInputMode;//数字输入模式

                };

},

 

           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;//文本输入模式

                };

            }

 

           };

    }

2、周期类:

 1Cperiodic

==================================================================

CPeriodic* iPeriodicTimer;

iPeriodicTimer = CPeriodic::NewL( CActive::EPriorityStandard );//这条语句一般在ConstructL()中

void CGraphicsAppView::StartTimer()//开始启动时钟

    {

    if ( !iPeriodicTimer->IsActive() )

        {iPeriodicTimer->Start( 1, 1,

            TCallBack( CGraphicsAppView::Period, this ) );//TcallBack是一个方法回调函数,从使用来看,他只能回调类中的静态方法。

        }

    }

TInt CGraphicsAppView::Period( TAny* aPtr )//周期启动函数,注意,这是个静态函数,但static只在头文件中才做了申明。

    {

    ( static_cast<CGraphicsAppView*>( aPtr ) )->DoPeriodTask();

    return ETrue;

    }

void CGraphicsAppView::DoPeriodTask()//周期真正在做的事情

    {

    // Update the screen

    CWindowGc& gc = SystemGc();

    gc.Activate( *DrawableWindow() );//如果要求清屏操作。增加gc.Clear();

    UpdateDisplay();///这个函数是周期需要实现的东西

    gc.Deactivate();

    }

void CGraphicsAppView::StopTiem()//停止时钟

    {

    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);  // 设定时钟请求为1秒

        User::WaitForRequest(timerStatus); // 等待这个请求

             // display the tick count

        _LIT(KFormat3,"Tick %d/n");

        console->Printf(KFormat3, i);

        }

3、Ttime

  TTime time; // time in microseconds since 0AD nominal Gregorian

   _LIT(KTxt2,"The time now is, ");

   console->Printf(KTxt2);

   time.HomeTime(); //设置时间为当前系统时间

   showTime(time);//显示当前时间

//----------------以下代码是人为给时间加10--------------

TTimeIntervalSeconds timeIntervalSeconds(10);

   time += timeIntervalSeconds;

   showTime(time); // print the time the request should complete

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

timer.At(timerStatus,time); //设定时钟请求为10秒

 User::WaitForRequest(timerStatus); //等待这个请求

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

   _LIT(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、字符串类:

TDesC是所有字符类的祖先

 

标准C语言

Symbian OS

让一个字符串进入2进制代码

Static char hellorom[]=”hello”

_LIT(khellorom,”hello”)

在栈中获得字符串的指针

Const char* helloptr=hellorom

TPtrC helloptr=khellorom

获得在栈中字符串的指针

Char hellostack[sizeof(hellorom)];

Strcpy(hellostack,hellorom);

TBufC<5> hellostack=khellorom;

获得在堆中字符串的指针

Char* helloheap=

(char *)malloc(sizeof(hellorom));

strcpy(helloheap,hellorom);

HBufC* helloheap=

Khellorom.AllocLC();

a)TPtrC相当于不变的字符串常量.

b)TPtr相当与String类型。Tbuf相当于char[]。前者与后者的唯一区别是,后者需要指定分配的栈空间大小。

C)HBufC* char*类似。分配的是堆上的空间。

HBufC* textResource;

//两种字符串附值方法

textResource = StringLoader::LoadLC( R_HEWP_TIME_FORMAT_ERROR );

textResource =iEikonEnv->AllocReadResourceL(R_EXAMPLE_TEXT_HELLO);

TBuf<32> timeAsText;

timeAsText = *textResource;

/* 数据类型转换*/


TBuf 
转换为 TPtrC16
    TBuf<32> tText(_L("2004/11/05 05:44:00"));
    TPtrC16 tPtrSecond=tText.Mid(17,2);

TPtrC16 转换为 TBufC16
    TPtrC16 tPtrSecond=tText.Mid(17,2);
    TBufC16<10> bufcs(tPtrSecond);

TBufC16 转换为  TPtr16
    TBufC16<10> bufcs(tPtrSecond);
    TPtr16 f=bufcs.Des();

TPtr16 转换为 TBuf
    TBuf<10> bufSecond;
    bufSecond.Copy(f);

TBuf 转换为 TPtr16
    TBuf<10> bufSecond(_L("abc"));
    TPtr16 f;
    f.Copy(bufSecond);

TBuf 转换为 TInt
    TInt aSecond;
    TLex iLexS(bufSecond);
    iLexS.Val(aSecond);

TInt 转换为 TBuf
    TBuf<32> tbuf;
    TInt i=200;
    tbuf.Num(i);

 1.串转换成数字
   TBuf16<20> buf(_L( "123" ) );
    TLex lex( buf );
    TInt iNum;
    lex.Val( iNum );
2.
数字转换成串
   TBuf16<20> buf;
   TInt iNum = 20;
   buf.Format( _L( "%d" ) , iNum  );
3.
symbian串转换成char
    char* p = NULL;
    TBuf8<20> buf( _L( "aaaaa" ) );
    p = (char *)buf.Ptr();

4.UTF-8转换成UNICODE
    CnvUtfConverter::ConvertToUnicodeFromUtf8( iBuf16 , iBuf8 );
5.UNICODE
转换成UTF-8
    CnvUtfConverter::ConvertFromUnicodeToUtf8( iBuf8 , iBuf16 );

6.char串转换成symbian
    char* cc = "aaaa";
    TPtrC8 a;
    a.Set( (const TUint8*)cc , strlen(cc) );

7、将TPtrc8TPtrc16之间转化

// 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 */

memset主要应用是初始化某个内存空间。用来对一段内存空间全部设置为某个字符。
memcpy是用于COPY源空间的数据到目的空间中,用来做内存拷贝可以拿它拷贝任何数据类型的对象。
strcpy只能拷贝字符串了,它遇到'/0'就结束拷贝。

 

strcpy
 
原型:extern char *strcpy(char *dest,char *src);
 
用法:#include <string.h>
 
功能:把src所指由NULL结束的字符串复制到dest所指的数组中。
 
说明:srcdest所指内存区域不可以重叠且dest必须有足够的空间来容纳src的字符串。
      
返回指向dest的指针。
      
memcpy
 
原型:extern void *memcpy(void *dest, void *src, unsigned int count);
 
用法:#include <string.h>
 
功能:由src所指内存区域复制count个字节到dest所指内存区域。
 
说明:srcdest所指内存区域不能重叠,函数返回指向dest的指针。
 
memset
 
原型:extern void *memset(void *buffer, int c, int count);
 
用法:#include <string.h>
 
功能:把buffer所指内存区域的前count个字节设置成字符c
 
说明:返回指向buffer的指针。

 

 

4、文件类和流操作

Location: s32file.h

文件模拟路径在C:/Symbian/8.0a/epoc32/wins下面。有C、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)      与文件服务器建立通信

RFs fsSession;

TInt fsret = fsSession.Connect(); // start a file session

       if (fsret != KErrNone)

              {console->Printf(KTxtConnectFailed,fsret);

              User::Leave(fsret);

              }

  2确定文件路径存在

fsSession.MkDirAll(KFullNameOfFileStore); // make sure directory exists

     

 

  3建立文件存储

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

       fsSession.Parse(aName,filestorename);

/*------------------------------------------------------------------------------------------------

 TDesC& aName。可以通过以下方式给aNAME赋值:
    _LIT(aName,"C://epoc32ex//data//SimpleClassToSimpleStream.dat");

----------------------------------------------------------------------------------------------*/

                            // construct file store object - the file to contain the

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

       CFileStore*     //如果EFileRead为读出流

 store = CDirectFileStore::ReplaceLC(fsSession,filestorename.FullName(),EFileWrite);

store->SetTypeL(KDirectFileStoreLayoutUid); // 设定存储种类

 

4将外部数据写入流::(记忆方式:>>指向就是数据流向)//假设:TSimple anXxx;

RStoreWriteStream outstream;

       TStreamId id = outstream.CreateLC(*store);

//----------------------------将标量写入数据流------------------

outstream<< anXxx;

    或者 aStream.WriteInt8L(anXxx);

    实际上这里使用了流的扩展化:(当输出不是普通的元数据时,使用这个扩展化)这是一个虚函数的重载

void TSimple::ExternalizeL(RWriteStream& aStream) const

       {

       aStream << iTheEnum;

       aStream << iBuffer;

       aStream.WriteInt32L(iIntValue);

       aStream.WriteUint32L(iUintValue);

       aStream.WriteReal64L(iRealValue);

       } 

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

     // 以下是将流改动提交到文件服务器。

       outstream.CommitL();

5将流读到外部数据:

       RStoreReadStream instream;

store->SetRootL(id);//可以将上面的已经存在的流作为流的根。好处是不必再创建流ID。实际上也就节省了内存。

// 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;//写入类对象数据。

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

void TSimple::InternalizeL(RReadStream& aStream)

       {

       aStream >> iTheEnum;

       aStream >> iBuffer;

      iIntValue  = aStream.ReadInt32L();

       iUintValue = aStream.ReadUint32L();

       iRealValue = aStream.ReadReal64L();

       } 

    //------------------------------输出流到其他数据元或类对象中----------------------------

     anXxx = TXxx(aStream.ReadInt8L());

  

6关闭文件服务通信

fsSession.Close()

   

5. 活动调度表

由于使用多线程来处理异步请求比较消耗系统资源,所以Symbian 使用了活动对象(Active Object)来解决异步请求的问题。
        
活动规划器(active scheduler)用于处理由活动对象提出的异步请求。它检测活动对象提出的异步请求,并安排活动对象的请求完成事件的执行顺序。活动规划器仅用一个事件处理线程来规划各个活动对象提出的事件请求,所以它要比多线程实现异步请求占用更少的资源。

1、   首先应该创建一个活动规划器对象,并把它安装到当前线程

       CActiveScheduler* scheduler = new(ELeave) CActiveScheduler();//创建一个活动规划器
   CleanupStack::PushL(scheduler);
   CActiveScheduler::Install(scheduler);//
安装活动规划器。
   TRAPD(error,doInstanceL());   //
具体安排的函数处理。

在具体的安排函数中一定要启动这个规划器

CActiveScheduler::Start();//这句话告诉活动规划器该等待对象的状态的改变

2 把自己加入活动规划器:一般这是一个类。可以在类的构造函数中申明下面代码。
                      CActiveScheduler::Add(this);

     //该类必须有一个继承来自public CActive, public MmsvSessionObserver

//在构造函数时,也可以宣布优先级别:TclassA::classA()  : CActive(0)    

3、返回改变事实:              

SetActive();  / / CActive类对象提交异步请求。

//这个请求说明对象的改变完成。就会触发CActive::RunL()

      4、这里的CActiveScheduler只管理了一个CActive对象,就是timeCount,可以用类似的方法实现多个CActive,并且都加入CActiveScheduler,CActiveScheduler将会等待所有加入它的CActive的状态的改变,其中有一个的状态改变就会去执行对应的活动对象的处理函数,当状态同时发生的时候,会通过对象的优先级来决定先调用谁的RunL函数.CActiveScheduler也是非抢占式的,当一个RunL函数还没有执行完的时候,如果另一个CActive的状态改变,会等待RunL执行完以后再执行另一个CActive的处理函数.

6、线程:

1、  创建一个等待的线程:

     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); //创建一个信号量,等待线程的正常结束

         res=thread.Create(KCountServerName,   // create new server thread

              CCountServServer::ThreadFunction, // 线程启动的主函数

              KDefaultStackSize,

              KDefaultHeapSize,

              KDefaultHeapSize,

              &semaphore // 最后是主函数的需要的参数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();

         }
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
提供的源码资源涵盖了Java应用等多个领域,每个领域都包含了丰富的实例和项目。这些源码都是基于各自平台的最新技术和标准编写,确保了在对应环境下能够无缝运行。同时,源码中配备了详细的注释和文档,帮助用户快速理解代码结构和实现逻辑。 适用人群: 适合毕业设计、课程设计作业。这些源码资源特别适合大学生群体。无论你是计算机相关专业的学生,还是对其他领域编程感兴趣的学生,这些资源都能为你提供宝贵的学习和实践机会。通过学习和运行这些源码,你可以掌握各平台开发的基础知识,提升编程能力和项目实战经验。 使用场景及目标: 在学习阶段,你可以利用这些源码资源进行课程实践、课外项目或毕业设计。通过分析和运行源码,你将深入了解各平台开发的技术细节和最佳实践,逐步培养起自己的项目开发和问题解决能力。此外,在求职或创业过程中,具备跨平台开发能力的大学生将更具竞争力。 其他说明: 为了确保源码资源的可运行性和易用性,特别注意了以下几点:首先,每份源码都提供了详细的运行环境和依赖说明,确保用户能够轻松搭建起开发环境;其次,源码中的注释和文档都非常完善,方便用户快速上手和理解代码;最后,我会定期更新这些源码资源,以适应各平台技术的最新发展和市场需求。 所有源码均经过严格测试,可以直接运行,可以放心下载使用。有任何使用问题欢迎随时与博主沟通,第一时间进行解答!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值