symbian电话薄开发.docx_第1页
symbian电话薄开发.docx_第2页
symbian电话薄开发.docx_第3页
symbian电话薄开发.docx_第4页
symbian电话薄开发.docx_第5页
已阅读5页,还剩7页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

/在AppUi类中构造容器void CHelloAppUi:ConstructL() BaseControl(); iAppContainer = CHelloContainer:NewL(ClientRect(); iAppContainer-SetMopParent(this);/在容器之间建立父子关系,这样子控件就可以访问父控件或其他子控件,父控件也可以访问子控件 AddToStackL(iAppContainer);/将Container推入栈顶,可以接收按键事件,如果想让其他容器接受事件,可以通过RemoveFromStack(iAppContainer)将当前容器从栈顶移出,将其他的容器推入栈顶,通过AddToStackL(iAppContainer2)/symbian编码诀窍:1)CleanupStack 机制是可以扩展的.面对所有的Leave事件.2)对HBufC变量分配内存后,试图删除该变量,删除后要将该变量设为Null.3)采用自己的TRAP时,不要忽略所有的错误TRAPD(err.DoSomething();if(err =KErrNotFound|err= KErrNone) /DoSomething();elseUser:Leave(err);4)Symbian中构造函数,析构函数不可能发生Leave.在symbian os中,构造函数将对象实例化,然后调用ConstructL()函数将成员数据实例化.5)Symbian指针表示所有权的转移,而引用所有权仍然属于原来的所有者./CCoeControl是所有控件的基类,在派生类中要实现四个函数void CHelloAppUi:public CCoeControl void SizeChanged();void Draw(); int CountComponentControls(); void ComponentControl(); /描述symbian下初始框架的函数,以下是symbian建立工程时产生的所有文件先描述头文件,然后是CPP文件.假定工程名称为Hello/头文件定义/CHelloApplication.h#ifndef HELLOAPPLICATION_H#define HELLOAPPLICATION_H#include class CHelloApplication:public CAknApplicationpublic: TUid AppDllUid() const;protected:CApaDocument* CreateDocumentL();#endif/CHelloDocument.h#ifndef HELLODOCUMENT_H#define HELLODOCUMENT_H#include class CHelloAppUi;class CEikApplication;class CHelloDocument:public CAknDocumentpublic: static CHelloDocument* NewL(CEikApplication& aApp); static CHelloDocument* NewLC(CEikApplication& aApp);CHelloDocument(); CHelloAppUi* CreateAppUiL();private:void ConstructL();CHelloDocument(CEikApplication& aApp);#endif/CHelloAppUi.h#ifndef HELLOAPPUI_H#define HELLOAPPUI_H#include class CHelloAppView;class CHelloAppUi:public CAknAppUipublic: void ConstructL(); CHelloAppUi(); CHelloAppUi(); void HandleCommandL(TInt aCommand);private: CHelloAppView* iAppView;#endif/CHelloAppView.h#ifndef HELLOAPPVIEW_H#define HELLOAPPVIEW_H#include class CHelloAppView:public CAknAppViewpublic: static CHelloAppView* NewL(const TRect& aRect); static CHelloAppView* NewLC(const TRect& aRect); CHelloAppView(); void Draw(const TRect& aRect) const;private:CHelloAppView(); void ConstructL(const TRect& aRect);#endif/具体的类实现/the definition of CHelloApplication:HelloApplication.cpp#include HelloApplication.h#include HelloDOcument.h#include const TUid KUidHelloApp = 0x08d5778;CApaDocument* CHelloApplication:CreateDocumentL() const return (static_cast(CHelloDocument:NewLC(*this);TUid CHelloApplication:AppDllUid() const return KUidHelloApp;/the definition of CHelloDocument:HelloDocument.cpp#include HelloDocument.h#include HelloAppUi.hstatic CHelloDocument* CHelloDocument:NewL(CEikApplication& aApp) CHelloDocument* self = NewLC(aApp); CleanupStack:Pop(self); return self;static CHelloDocument* CHelloDocument:NewLC(CEikApplication& aApp) CHelloDocument* self = new(ELeave)CHelloDocument(aApp); CLeanupStack:PushL(self); self-ConstructL();return self;CHelloDocument:CHelloDocument()CHelloDocument:ConstructL()CHelloDocument:CHelloDocument(CEikApplication& aApp):CAknDocument(aApp)CHelloAppUi* CHelloDocument:CreateAppUiL() return (static_cast(new(ELeave)CHelloAppUi);/the definition of CHelloAppUi:HelloAppUi.cpp#include HelloAppUi.h#include HelloAppView.h#include Hello.hrh#include Hello.pan#include #include CHelloAppUi:CHelloAppUi()CHelloAppUi:CHelloAppUi() if(iAppView) iEikonEnv-RemoveFormStackL(iAppView);delete iAppView;iAppView = NULL; CHelloAppUi:ConstructL()BaseConstructL(); iAppView = CHelloAppView:NewL(const TRect& arect); AddToStackL(iAppView);void CHelloAppUi:HandleCommandL(TInt aCommand) switch(aCommand) case EEikCmdExit: case EAknSoftKeyExit:Exit();break; case EHelloCommand1: _LIT(message,Command1); CAknInformationNote* informationnote = new(ELeave)CAknInformationNote; informationNote-ExecuteLD(message);break; default:Panic(EHelloBasicUi);break; /the definition of CHelloAppView:HelloAppView.h#include HelloAppView.hstatic CHelloAppView* CHelloAppView:NewL(const TRect& aRect) CHelloAppView* self = NewLC(aRect); CleanupStack:Pop(self); return self;CHelloAppView:CHelloAppView()static CHelloAppView* CHelloAppView:NewLC(const TRect& aRect) CHelloAppView* self = new(ELeave)CHelloAppView; CleanupStack:PushL(self); self-ConstructL(); return self;CHelloAppView:CHelloAppView()void CHelloAppView:ConstructL(const TRect& aRect) CreateWindowL(); SetRect(aRect); ActivateL();/注意函数后面的L千万不要丢掉.void CHelloAppView:Draw(const TRect& aRect) constCWindowGc& gc = SystemGc();/SystemGc是CCoeControl的函数,用来获取图形上下文gc.SetBrushColor(KRgbRed);gc.SetBrushStyle(CGraphicsContext:ESolidBrush);gc.DrawRect(aRect);gc.Clear(Rect();/the definition of Hello.hrh#ifndef HELLO_HRH#define HELLO_HRHenum THelloIds EHelloCommand1 = 0x0600;#endif/the definition of Hello.pan#ifndef HELLO_PAN#define HELLO_PAN#endif/框架到此描述结束./容器类Container中的内容精要小结:在Container中显示两个Label的方法:1)首先将两个Label指针作为Container类的私有成员变量:private:CEikLabel* iLabel;CEikLabel* iToDoLabel;2)Container类中的四个方法,否则Label控件不会显示:void SizeChanged(); /这个函数没有 const限制void Draw(const TRect& aRect) const;virtual TInt CountComponentControls() const;virtual CCoeControl* ComponentControl(TInt aIndex) const;/虚函数,在基类中声明,在派生类中定义,但是在派生类中不需要virtual 标示.具体的实现函数:CCoeControl* CHelloCOntainer:ComponentControl(TInt aIndex) constSwitch(aIndex)case 0:return iLabel;case 1:return iToDoLabel;default:return NULL;TInt CHelloContainer:CountComponentControls( )constreturn 2;void CHelloContainer:SizeChanged() /设定控件的位置iLabel-SetExtent(TPoint(10,10),iLabel-MinimumSize();iToDoLabel-SetExent(TPoint(10,100),iToDoLabel-MinimumSize();/注意:SetExent函数没有以L结尾.必须重写这两个方法,要不Label控件不会显示void CHelloContainer:Draw( const TRect& aRect) const/屏幕的显示范围大概是(0,0)到(120,150).最好不要超出CWindowsGc& gc = SystemGc();TRect rect = Rect();gc.Clear(rect);gc.SetPenStyle( CGraphicsContext:ENullPen);gc.SetBrushColor(KRgbRed);gc.SetBrushStyle(CGraphicsContext:ESolidBrush);gc.DrawRect(aRect); Container中的ConstructL( )方法:void CHelloContainer:ConstructL() CreateWindowL(); iLabel = new (ELeave) CEikLabel; iLabel-SetContaierWindowL(*this);/将不用有窗口的控件与窗口相联/表示这两个控件显示在那个窗口上,参数是容器Container iLabel-SetTextL(_LIT(“iLabel”); iLabel-SetUnderlining(ETrue); iToDoLabel = new(ELeave) CEikLabel; iToDoLabel-SetContainerWindowL(*this); iToDoLabel-SetTextL(_LIT(“iToDoLabel”); SetRect(aRect); ActivateL();/激活窗口,也就是调用Draw(),SizeChanged()函数,开始绘制窗口Avkon视图切换架构详细分析笔记:2007.3.61):首先与传统的视图架构相比,多了view视图类;一共有五个类:Application,Document;AppUi;View;Container;如果程序中有多个视图,则view与container类要成对实现.且视图的切换在类AppUi的ConstructL()函数中.通讯录的删除主要通过引擎类CPbkContactEngine来实现,引擎类的成员iEngine也是在AppUi的ConstructL()函数中定义的.主要几个类的作用:AppUi:控制视图类的定义,切换.以及Engine类的定义实现.View:AppUi类与Container类之间的桥梁.同时包含Engine类的引用.Container:容器类主要实现窗口中的控件如:列表,图标等等Engine:成员函数的具体实现,通过view中的HandleCommandL()函数调用2):在传统架构中,iContainer是作为AppUi的私有成员的.而在Avkon视图切换架构中:iContainer是作为View类的私有成员的.iEngine是AppUi的私有成员.3):在View类的ConstructL()函数中不能创建iContainer,切记:在此函数中仅仅传送资源文件.4):在view类的HandleCommandL()函数中,通过按键事件来调用AppUi类与Engine类中的菜单或者命令等等.5):(个人观点)在Avkon视图切换架构中,view类相当于AppUi与Container之间的桥梁.与此同时通过view类来调用Container与Engien类,Container类与传统视图架构中的作用差不多,主要是列表的显示以及图形的绘制等等.6): /在container.cpp文件里面Void CPhoneBkExContainer:ConstructL(const TRect& aRect) CreateWindowL(); /控制窗口关联 SetRect(aRect); /设置窗口范围 /create the list box iListBox = new (ELeave)CAknDoubleStyleListBox(); /申请空间 iListBox-ConstructL(this,EAknListBoxSelectionList); /调用构造函数 iListBox-SetContainerWindowL(*this);/将列表与窗口相关联 iListBox-CreateScrollBarFrameL(ETrue);/建立滚动条 iListBox-ScrollBarFrame()-SetScrollBarVisibilityL(CEikScrollBarFrame:EOff); /设置滚动条默认属性 iListBox-SetRect(Rect();/设置滚动条的范围 ActivateL();/激活窗口 /上面是列表的创建方法,下面是Label的创建方法Void CPhoneBkExContainer:ConstructL(const TRect& aRect)HBufC* labelText = StringLoader:LoadLC(R_VIEW2_TEXT);CreateWindowL();iLabel = new (ELeave) CEikLabel;/声请空间iLabel-SetContainerWindowL(*this); /将图标与窗口相关联iLabel-SetTextL(*labelText); /给相应的图标命名CleanupStack:PopAndDestroy(); SetRect(aRect);ActivateL();7):/view.cpp文件里面,创建列表(listbox)与图标(label)方法基本相似Void CPhoneBkExView:ConstructL()BaseConstructL(R_PHONEBKEX_VIEW);/通讯录学习笔记总结:2007.3.7/打开关闭通讯录CContactDatabase:OpenL()函数有两个重载函数L参数不同)无参数:打开默认数据库有参数:打开参数指定的数据库CContactDatabase* contactsDb = CContactDatabase:OpenL();CleanupStack:PushL(contactsDb);TInt numberOfContacts = contactsDb-CountL();CleanupStack:PopAndDestroy(contactsDb);/新建数据库CContactDatabase:CreateL():如果数据库存在,以KErrAlreadyExists退出CContactDatabase:ReplaceL():如果数据库已经存在,就替换原来的数据库.TFileName contactDbFilePath;CContactDatabase* newDefaultContactDb;if( CContactDatabase:FindContactFile(contactDbFilePath)/是否存在默认数据库newDefaultContactDb = CContactDatabse:ReplaceL();elsenewDefaultContactDb = CContactDatabase:CreateL():CleanupStack:PushL(newDefaultContactDb);/此处添加自己的代码CleanupStack:PopAndDestroy(newDefaultContactDb);/遍历通讯录项通过类TContactIter来实现,每个函数用通讯录项ID(TContactItemId)进行操作CContactDatabase* contactsDb = CContactDatabase:OpenL();CleanupStack:PushL(contactsDb);TContactIter iter(*contactsDb); /类似游标TContactItemId cardId;while(cardId = iter.NextL()!= KNullContactId) CContactItem* card = contacsDb-ReadContactL(cardId); CleanupStack:PushL(card);/添加自己的代码 contactsDb-CloseContactL(card-Id(); CleanupStack:PopAndDestroy():CleanupStack:PopAndDestr

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论