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、周期类:
1、Cperiodic
==================================================================
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( 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 %dn");
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 upnThe 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、将TPtrc8与TPtrc16之间转化
// Get a iBuf8 from a iBuf16 (data are not modified)
TPtrC8 ptr8(reinterpret_cast(iBuf16.Ptr()),(iBuf16.Size()*2));
iBuf8=ptr8;
// Get a iBuf16 from a iBuf8 (data are not modified)
TPtrC16 ptr16(reinterpret_cast(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只能拷贝字符串了,它遇到' |