// Chapter 6 Examples
//
// Copyright (c) Symbian Software Ltd 1999 - 2007. All rights reserved.
//
// This file contains the source for the various examples in Chapter 6.
// It uses the console. Note that this example is made to run on the emulator only.
#include <e32base.h>
#include <e32cons.h>
CConsoleBase* console;
/*----------------------------------------------------------------------------
Stub example from console section.
-----------------------------------------------------------------------------*/
void PressAnyKey()
{
_LIT(KAnyKey,"[Press any key]\n");
console->Printf(KAnyKey);
console->Getch();
}
/*------------------------------------------------------------------------
From example comparing string handling in C and Symbian OS.
-------------------------------------------------------------------------*/
_LIT(KNamePrefix,"Name: ");
void makeName(const TDesC& aName)
{
TBuf<80> str;
str.Copy(KNamePrefix);
str.Append(aName);
_LIT(KFormatStr,"str = %S\n");
console->Printf(KFormatStr,&str);
}
void MainFunc()
{
_LIT(KFunctionStr,"---MainFunc()---");
console->Printf(KFunctionStr);
makeName(_L("Sharon")); // Note that this demonstrates _L, but _LIT should be used instead
PressAnyKey();
}
/*-------------------------------------------------------------------------------
Example from heap descriptor section
--------------------------------------------------------------------------------*/
void heapDesExampleL()
{
_LIT(KFunctionStr,"---heapDesExampleL()---");
console->Printf(KFunctionStr);
_LIT(KString1,"Test");
_LIT(KString2,"My Heap String");
HBufC* myHeapDes = HBufC::NewL(KString1().Length());
CleanupStack::PushL(myHeapDes);
*myHeapDes = KString1;
_LIT(KFormat1,"myHeapDes = \"%S\" length = %d\n");
console->Printf(KFormat1,myHeapDes,myHeapDes->Length());
myHeapDes->ReAllocL(KString2().Length()); // if you do not do this,
// next line would panic
/* Replace entire string in the HBufC */
*myHeapDes = KString2;
console->Printf(KFormat1,myHeapDes,myHeapDes->Length());
/* Get a modifiable pointer to the HBufC's data buffer */
TPtr myPtr = myHeapDes->Des();
_LIT(KString3,"Hello");
_LIT(KString4,"!!!");
/* Modify the HBufC buffer area through the TPtr, using Copy()
* and Append()
*/
myPtr.Copy(KString3);
myPtr.Append(KString4);
_LIT(KFormat2,"myHeapDes = \"%S\" length = %d myPtr = \"%S\" length = %d\n");
console->Printf(KFormat2,myHeapDes,myHeapDes->Length(), &myPtr,myPtr.Length());
CleanupStack::PopAndDestroy(myHeapDes);
PressAnyKey();
}
/*-------------------------------------------------------------------------
Examples from 'Touring the Descriptor Methods' section.
--------------------------------------------------------------------------*/
void CompareExample()
{
_LIT(KFunctionStr,"---CompareExample()---");
console->Printf(KFunctionStr);
_LIT(KString1,"My String");
_LIT(KString2,"MY STRING");
_LIT(KString3,"Another string");
TBuf<20> str1(KString1);
TBuf<20> str2(KString2);
TInt res;
/* Compare shows a match since str1 is initialized to KString1 */
res = str1.Compare(KString1);
_LIT(KFormatCompare1,"Compare() string 1 and string 1 = %d\n");
console->Printf(KFormatCompare1, res);
/* Compare shows a no match since str1 and str2 contents do
* not exactly match
*/
res = str1.Compare(str2);
_LIT(KFormatCompare2,"Compare() string 1 and string 2 = %d\n");
console->Printf(KFormatCompare2, res);
/* Compare shows a match since a folded compare is case insensitive */
res = str1.CompareF(str2);
_LIT(KFormatCompare3,"CompareF() string 1 and string 2 = %d\n");
console->Printf(KFormatCompare3, res);
/* Compare shows a mismatch since string 1 and 3 are different */
res = str1.Compare(KString3);
_LIT(KFormatCompare4,"Compare() string 1 and string 3 = %d\n");
console->Printf(KFormatCompare4, res);
PressAnyKey();
}
void FindExample()
{
_LIT(KFunctionStr,"---FindExample()---");
console->Printf(KFunctionStr);
_LIT(KString1,"This is a test string");
_LIT(KString2,"test");
_LIT(KString3,"car");
_LIT(KString4,"TEST");
TBuf<40> buf(KString1);
TInt res;
/* Find returns position of "test" in KString1 */
res = buf.Find(KString2);
_LIT(KFormat1,"Find of string 2 in string 1 res = %d\n");
console->Printf(KFormat1,res);
/* "car" does not occur in KString1, so KErrNotFound reported */
res = buf.Find(KString3);
_LIT(KFormat2,"Find of string 3 in string 1 res = %d\n");
console->Printf(KFormat2,res);
/* Since FindF does a fold compare, "TEST" is found and position
* is returned
*/
res = buf.FindF(KString4);
_LIT(KFormat3,"Find of string 4 in string 1 res = %d\n");
console->Printf(KFormat3,res);
PressAnyKey();
}
void MatchExample()
{
_LIT(KFunctionStr,"---MatchExample()---");
console->Printf(KFunctionStr);
_LIT(KString1,"This is test string A");
_LIT(KString2,"This is test string ?");
_LIT(KString3,"*is test string ?");
_LIT(KString4,"*");
_LIT(KString5,"*B");
TBuf<40> buf(KString1);
TInt res;
/* A match since ? indicates any single character */
res = buf.Match(KString2);
_LIT(KFormat1,"Match: string 2 and string 1 res = %d\n");
console->Printf(KFormat1,res);
/* A match using '*' and '?' in string */
res = buf.Match(KString3);
_LIT(KFormat2,"Match: string 3 and string 1 res = %d\n");
console->Printf(KFormat2,res);
/* '*' matches any string */
res = buf.Match(KString4);
_LIT(KFormat3,"Match: string 4 and string 1 res = %d\n");
console->Printf(KFormat3,res);
/* no match since KString1 does not end in 'B' */
res = buf.Match(KString5);
_LIT(KFormat4,"Match: string 5 and string 1 res = %d\n");
console->Printf(KFormat4,res);
PressAnyKey();
}
void SubstringExample()
{
_LIT(KFunctionStr,"---SubstringExample()---");
console->Printf(KFunctionStr);
_LIT(KString1,"This is my string");
TBufC<40> buff(KString1);
TPtrC SubStr= buff.Left(4);
/* Get left 4 characters of string */
_LIT(KFormat1,"Left(4): SubStr = \"%S\"\n");
console->Printf(KFormat1,&SubStr);
/* Get right 3 characters of string */
SubStr.Set(buff.Right(3));
_LIT(KFormat2,"Right(3): SubStr = \"%S\"\n");
console->Printf(KFormat2,&SubStr);
/* get 6 characters in middle, starting at position 8 */
SubStr.Set(buff.Mid(8,6));
_LIT(KFormat3,"Mid(8,6): SubStr = \"%S\"\n");
console->Printf(KFormat3,&SubStr);
PressAnyKey();
}
void CopyExample()
{
_LIT(KFunctionStr,"---CopyExample()---");
console->Printf(KFunctionStr);
TUint8 binData[6] = {0xB0,0xB1,0xB2,0xB3,0xB4,0xB5};
/* Copy standard C array into binary descriptor */
TBuf8<sizeof(binData)> binDes;
binDes.Copy(binData,sizeof(binData));
_LIT(KFormat1,"binDes[0]=%x binDes[1]=%x\n");
console->Printf(KFormat1,binDes[0],binDes[1]);
/* Copy binary descriptor to another 8 bit binary descriptor */
TBuf8<20> buf8;
buf8.Copy(binDes);
_LIT(KFormat2,"buf8[0]=%x buf8[1]=%x\n");
console->Printf(KFormat2,buf8[0],buf8[1]);
/* Copy literal into descriptor */
_LIT(KString1,"My string");
TBuf<20> buf16;
buf16.C
没有合适的资源?快使用搜索试试~ 我知道了~
Symbian OS 软件开发——应用C++开发智能手机应用程序入门
共141个文件
cpp:50个
h:24个
rss:16个
4星 · 超过85%的资源 需积分: 9 1.0k 下载量 79 浏览量
2008-04-07
11:15:12
上传
评论
收藏 138KB RAR 举报
温馨提示
《Symbian OS 软件开发——应用C++开发智能手机应用程序入门》教程所配源代码。
资源推荐
资源详情
资源评论
收起资源包目录
Symbian OS 软件开发——应用C++开发智能手机应用程序入门 (141个子文件)
runtestsS60.bat 153B
runtestsUIQ.bat 146B
runexample.bat 74B
run.bat 68B
runtests.bat 65B
tests.cpp 19KB
weatherinfo.cpp 7KB
weatherinfo.cpp 7KB
Active.cpp 5KB
textbuffserver.cpp 4KB
textbuffclient.cpp 3KB
simpleEx_view.cpp 3KB
dialog.cpp 3KB
simpleEx_view.cpp 3KB
simpleEx_view.cpp 2KB
simpleEx_view.cpp 2KB
dialog.cpp 2KB
countdown.cpp 2KB
countdown.cpp 2KB
simpleEx_ui.cpp 2KB
simpleEx_view.cpp 1KB
simpleEx_ui.cpp 1KB
simpleEx_ui.cpp 1KB
simpleEx_view.cpp 1KB
simpleEx_view.cpp 1KB
simpleEx_view.cpp 1KB
simpleEx_ui.cpp 856B
simpleEx_doc.cpp 615B
simpleEx_doc.cpp 615B
simpleEx_doc.cpp 615B
simpleEx_doc.cpp 615B
simpleEx_doc.cpp 615B
simpleEx.cpp 595B
simpleEx.cpp 595B
simpleEx.cpp 595B
simpleEx.cpp 595B
simpleEx.cpp 595B
simpleEx_app.cpp 585B
simpleEx_app.cpp 585B
simpleEx_app.cpp 585B
simpleEx_app.cpp 585B
simpleEx_doc.cpp 570B
simpleEx_ui.cpp 566B
simpleEx_ui.cpp 560B
simpleEx_ui.cpp 560B
simpleEx_ui.cpp 554B
simpleEx_app.cpp 545B
simpleEx_app.cpp 544B
simpleEx_doc.cpp 442B
simpleEx.cpp 426B
simpleEx.cpp 424B
simpleEx.cpp 424B
simpleEx_app.cpp 412B
simpleEx_doc.cpp 367B
simpleEx_app.cpp 348B
SimpleEx.h 3KB
SimpleEx.h 2KB
SimpleEx.h 2KB
SimpleEx.h 2KB
SimpleEx.h 2KB
SimpleEx.h 2KB
SimpleEx.h 2KB
SimpleEx.h 1KB
textbuffserver.h 1KB
weatherinfo.h 1KB
weatherinfo.h 1KB
active.h 797B
countdown.h 589B
countdown.h 589B
textbuffclient.h 511B
textbuff.h 500B
SimpleExUid.h 136B
SimpleExUid.h 136B
SimpleExUid.h 136B
SimpleExUid.h 136B
SimpleExUid.h 136B
SimpleExUid.h 136B
SimpleExUid.h 136B
SimpleExUid.h 136B
SimpleEx.hrh 473B
SimpleEx.hrh 425B
SimpleEx.hrh 373B
SimpleEx.hrh 359B
SimpleEx.hrh 339B
SimpleEx.hrh 322B
SimpleEx.hrh 288B
SimpleEx.hrh 225B
bld.inf 164B
bld.inf 40B
bld.inf 40B
bld.inf 36B
bld.inf 36B
bld.inf 35B
bld.inf 34B
bld.inf 34B
Bld.inf 32B
bld.inf 29B
simpleExGui.mmp 836B
simpleExWthr.mmp 822B
simpleExForm.mmp 789B
共 141 条
- 1
- 2
资源评论
- valiantred2013-04-14下了没看,想看时发现塞班已经玩完了
- 啊啊你妹2014-01-04总的来说,不错,不过过时了
lxystar2003
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 基于STM8S103F3P6+STM8S207C8T6+STM32F103 单片机三合一最小系统开发板硬件(原理图+PCB)工程
- 基于C语言实现的打印杨辉三角
- 基于ASIO的插件式服务器,支持TCP,UDP,串口,Http,Websocket统一化的数据接口,隔离开发人员和IO之间的操作
- stm32 usb接口通信
- Chessmate是一款完全免费的国际象棋学习软件,支持引擎分析,学开局、残局、棋书解读、大数据分析等功能
- 总结整理的Android面试Java基础知识点面试资料精编汇总文档资料合集.zip
- .android_lq
- FDN5632N-VB一款SOT23封装N-Channel场效应MOS管
- 毛老板-2404250902.amr
- Java类加载流程(双亲委派)流程图.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功