S60平台的视图架构中,核心组件是AppUi类 视图类 容器类
AppUi类------(继承自CAknViewAppUi)
我们定义的AppUi类继承自CAknViewAppUi是专门为视图应用程序准备的AppUi类,这个类实现了一些视图管理功能例如视图的注册,注销,切换等
视图类 -------(继承自CAknView)
CAknView直接继承自CBase类,是Avkon中的视图基类,S60平台的视图类都要从该类派生,该类实现了MCoeView接口类,实现了该接口中定义的一个纯虚函数,并返回了这个视图的唯一标识,视图服务器通过这个标识访问和控制每个视图
容器类 -------(继承自CCoeControl)
容器类派生自CCoeControl类,是一个复合的控件,可以理解成包含了界面上其他控件的控件
从视图的角度看,视图只负责显示和控制一个复合控件,并且把需要响应的事件都交给该复合控件处理,而复合控件把这些事件分发给各个子控件.
在我的示例程序TestMultiView中有
TestMultiView,
TestMultiViewDocument,
TestMultiViewApplication,
TestMultiViewAppUi,
TestMultiViewAppView,
TestMultiViewAppView111,
TestMultiViewAppContainer,
TestMultiViewAppContainer111一共八个类
其中的前面四个类是应用程序框架类,所有的 Symbian OS都使用这种框架
TestMultiViewAppContainer,TestMultiViewAppContainer111是俩个容器类。分别在俩个视图中显示,他们都是控件继承自CCoeControl
下面我们依次分析各个类:
1:TestMultiViewAppUi:
// INCLUDES
#include <aknviewappui.h>//appview
#include <akntabobserver.h>
// FORWARD DECLARATIONS
class CTestMultiViewAppContainer;
#include <akntabgrp.h>
#include <aknnavide.h>
class CTestMultiViewAppUi : public CAknViewAppUi, MAknTabObserver
{
public:
void ConstructL();
~CTestMultiViewAppUi();
public:
void TabChangedL(TInt aIndex);//
private:
void DynInitMenuPaneL(TInt aResourceId,CEikMenuPane* aMenuPane);
private:
void HandleCommandL(TInt aCommand);
virtual TKeyResponse HandleKeyEventL(
const TKeyEvent& aKeyEvent,TEventCode aType);
CArrayFix<TCoeHelpContext>* HelpContextL() const;
void PrivacyStatementL();
static HBufC * ReadUnicodeFileL(RFs& aFs, const TDesC& aFileName);
private:
CAknNavigationControlContainer* iNaviPane;//导航面板
CAknTabGroup* iTabGroup;//导航面板的标签组
CAknNavigationDecorator* iDecoratedTabGroup;//导航面板子控件
};
#endif // __TESTMULTIVIEWAPPUI_h__
// End of File
实现如下:
#include "TestMultiView.pan"//*.pan文件是为应用程序创建一份应急代码,字面意思应急代码在开发过程中显示程序的错误用的,但是具体我也没有用到过,所以也不知道如何解释更好些。
//*********************************
#include "TestMultiViewApplication.h"//应用程序的头文件
#include "TestMultiViewAppUi.h"//自己的头文件
#include "TestMultiViewAppView.h"//view1的头文件
#include "TestMultiViewAppView111.h"//view2的头文件
#include <TestMultiView_0xEC2949F0.rsg>//资源标志符头文件
#include "TestMultiView.hrh"//*.hrh是可以被C++文件(包括头文件和源文件)和Symbian资源文件(包括*.rss和*.rh)包含的头文件,其内基本是预处理语句和enum枚举语句,这些枚举语句往往是菜单、工具条等的命令索引值,在switch…case语句中使用;
#include <stringloader.h>//字符串资源加载头文件
#include <f32file.h>//文件系统的头文件
#include <hlplch.h>//帮助头文件
#include <aknmessagequerydialog.h>//对话框定义文件
#include <bautils.h>//和文件读取有关的
#include <avkon.hrh>
#include <charconv.h>
#include "TestMultiView_0xEC2949F0.hlp.hrh"
//**********************************
//_LIT( KFileName, "C://private//EC2949F0//TestMultiView.txt" );
//_LIT( KText, "Hello World!");
// ============================ MEMBER FUNCTIONS ===============================
// -----------------------------------------------------------------------------
// CTestMultiViewAppUi::ConstructL()
// Symbian 2nd phase constructor can leave.
// -----------------------------------------------------------------------------
//
void CTestMultiViewAppUi::ConstructL()
{
// Initialise app UI with standard value.
//用标准之来初始化应用程序界面
BaseConstructL(CAknAppUi::EAknEnableSkin);
// 获取指向状态面板的指针
CEikStatusPane* sp = StatusPane();
// 得到默认的指向导航面板的指针
iNaviPane = (CAknNavigationControlContainer*)sp->ControlL(TUid::Uid(EEikStatusPaneUidNavi));
// 导航面板的标签组已经从资源文件里面读取了出来压到了导航面板维护的数组里面了.
// 用函数 ResourceDecorator()来得到指向导航面板子控件的指针.
// 本应用拥有导航面板子控件所以有责任去删除它.
iDecoratedTabGroup = iNaviPane->ResourceDecorator();//得到导航面板子控件
if (iDecoratedTabGroup)
{
iTabGroup = (CAknTabGroup*) iDecoratedTabGroup->DecoratedControl();//得到导航面板标签组
iTabGroup->SetObserver( this );//给导航面板标签组家观察者
}
CTestMultiViewAppView* view1 = new (ELeave) CTestMultiViewAppView;
CleanupStack::PushL( view1 );
view1->ConstructL();
AddViewL( view1 ); // transfer ownership to CAknViewAppUi
CleanupStack::Pop(); // view1
CTestMultiViewAppView111* view2 = new (ELeave) CTestMultiViewAppView111;
CleanupStack::PushL( view2 );
view2->ConstructL();
AddViewL( view2 ); // transfer ownership to CAknViewAppUi
CleanupStack::Pop(); // view2
SetDefaultViewL(*view1);
//PrivacyStatementL();
}
CTestMultiViewAppUi::~CTestMultiViewAppUi()
{
delete iDecoratedTabGroup;
}
void CTestMultiViewAppUi::DynInitMenuPaneL(
TInt /*aResourceId*/,CEikMenuPane* /*aMenuPane*/)
{
}
TKeyResponse CTestMultiViewAppUi::HandleKeyEventL(
const TKeyEvent& aKeyEvent,TEventCode aType)
{
if ( iTabGroup == NULL )
{
return EKeyWasNotConsumed;
}
if ( aKeyEvent.iCode == EKeyLeftArrow || aKeyEvent.iCode == EKeyRightArrow )
{
return iTabGroup->OfferKeyEventL( aKeyEvent, aType );
}
else
{
return EKeyWasNotConsumed;
}
}
void CTestMultiViewAppUi::HandleCommandL(TInt aCommand)
{
switch ( aCommand )
{
case EEikCmdExit:
{
Exit();
break;
}
// case EMultiViewExamCmdAppTest://swb
// {
// iEikonEnv->InfoMsg(_L("test"));
// break;
// }
case EHelp:
{
CArrayFix<TCoeHelpContext>* buf = CCoeAppUi::AppHelpContextL();
HlpLauncher::LaunchHelpApplicationL(iEikonEnv->WsSession(), buf);
}
break;
case EAbout:
{
CAknMessageQueryDialog* dlg = new (ELeave)CAknMessageQueryDialog();
dlg->PrepareLC(R_ABOUT_QUERY_DIALOG);
HBufC* title = iEikonEnv->AllocReadResourceLC(R_ABOUT_DIALOG_TITLE);
dlg->QueryHeading()->SetTextL(*title);
CleanupStack::PopAndDestroy(); //title
HBufC* msg = iEikonEnv->AllocReadResourceLC(R_ABOUT_DIALOG_TEXT);
dlg->SetMessageTextL(*msg);
CleanupStack::PopAndDestroy(); //msg
dlg->RunLD();
}
break;
// TODO: Add Your command handling code here
default:
break;
}
}
//这个是当按键的时候切换view1 和view2的
void CTestMultiViewAppUi::TabChangedL(TInt aIndex)
{
ActivateLocalViewL(TUid::Uid(iTabGroup->TabIdFromIndex(aIndex)));
}
CArrayFix<TCoeHelpContext>* CTestMultiViewAppUi::HelpContextL() const
{
// Note: help will not work if the application uid3 is not in the
// protected range. The default uid3 range for projects created
// from this template (0xE0000000 - 0xEFFFFFFF) are not in the protected range so they
// can be self signed and installed on the device during testing.
// Once you get your official uid3 from Symbian Ltd. and find/replace
// all occurrences of uid3 in your project, the context help will
// work.
CArrayFixFlat<TCoeHelpContext>* ctxs = new(ELeave)CArrayFixFlat<TCoeHelpContext>(1);
CleanupStack::PushL(ctxs);
ctxs->AppendL(TCoeHelpContext(KUidTestMultiViewApp, KGeneral_Information));
CleanupStack::Pop(ctxs);
return ctxs;
}
/*
void CTestMultiViewAppUi::PrivacyStatementL()
{
// Note: to see privacy statement in emulator, copy
// PrivacyStatement.txt from group/ directory to
// %EPOCROOT%/Epoc32/release/winscw/udeb/z/private/ef8f8e83/
// Also note that on emulator you can't modify files on Z: drive,
// so even if you answer Yes to privacy statement, it will popup
// dialog every time you launch application. But on device it will work
// as expected.
HBufC * fileName = StringLoader::LoadLC(R_PRIVACY_STATEMENT_FILENAME_TEST);//加载文件
RFs &fs= iCoeEnv->FsSession();//连接服务器
// Make full path to privacy statement
TFileName fullFileName;
TFileName privatePath;
fs.PrivatePath(privatePath);
TParse parser;
TFileName processFileName(RProcess().FileName());
User::LeaveIfError(parser.Set(*fileName, &privatePath, &processFileName));
fullFileName = parser.FullName();
CleanupStack::PopAndDestroy(fileName);
if(BaflUtils::FileExists(fs, fullFileName))
{
RBuf text(CTestMultiViewAppUi::ReadUnicodeFileL(fs, fullFileName));
CleanupClosePushL(text);
CAknMessageQueryDialog *dialog = CAknMessageQueryDialog::NewL(text);
if(dialog->ExecuteLD(R_PRIVSTMT_DIALOG_TEST) == EAknSoftkeyYes)
{
BaflUtils::DeleteFile(fs, fullFileName);
}
CleanupStack::PopAndDestroy(&text);
}
}
*/
HBufC * CTestMultiViewAppUi::ReadUnicodeFileL(RFs& aFs, const TDesC& aFileName)
{
RFile file;
User::LeaveIfError(file.Open(aFs, aFileName, EFileShareReadersOnly | EFileStreamText | EFileRead));
CleanupClosePushL(file);
TInt size;
User::LeaveIfError(file.Size(size));
RBuf8 tmp;
tmp.CreateL(size);
CleanupClosePushL(tmp);
User::LeaveIfError(file.Read(tmp));
CCnvCharacterSetConverter * converter = CCnvCharacterSetConverter::NewLC();
converter->PrepareToConvertToOrFromL(KCharacterSetIdentifierUtf8, aFs);
HBufC *text = HBufC::NewL(size);
TInt state = CCnvCharacterSetConverter::KStateDefault;
TPtrC8 remainderOfForeignText(tmp);
for(;;)
{
TPtr textPtr(text->Des());
TInt retValue = converter->ConvertToUnicode(textPtr, remainderOfForeignText, state);
if(retValue == CCnvCharacterSetConverter::EErrorIllFormedInput)
User::Leave(KErrCorrupt);
else if(retValue < 0)
User::Leave(KErrGeneral);
if(retValue == 0)
break;
remainderOfForeignText.Set(remainderOfForeignText.Right(retValue));
}
CleanupStack::PopAndDestroy(converter);
CleanupStack::PopAndDestroy(2);
return text;
}
TestMultiViewAppView类的定义如下:
// INCLUDES
#include <aknview.h>
const TUid KViewId = {1}; //该视图在本应用程序中的唯一标示
class CTestMultiViewAppContainer;
class CTestMultiViewAppView : public CAknView//
{
public:
void ConstructL(); //第二阶段构造函数
~CTestMultiViewAppView();
public:
TUid Id() const; //从MCoeView继承而来的函数,负责返回视图的标示
void HandleCommandL(TInt aCommand); //用于处理菜单命令
void HandleClientRectChange(); //用于相应客户区域的变化
private:
void DoActivateL(const TVwsViewId& aPrevViewId,TUid aCustomMessageId,
const TDesC8& aCustomMessage); //在视图激活之前系统会调用这个函数
void DoDeactivate(); //当由本视图切换到其他视图时,系统会调用本视图的本函数
private:
CTestMultiViewAppContainer* iContainer;//指向视图容器对象的指针
};
#endif
实现如下:
CTestMultiViewAppView::~CTestMultiViewAppView()
{
if ( iContainer )
{
AppUi()->RemoveFromViewStack(*this, iContainer );
}
delete iContainer;
};
TUid CTestMultiViewAppView::Id() const
{
return KViewId;
};
//负责处理用户命令 主要是菜单命令 用户输入菜单命令的时候,系统首先调用本类
//命令分为系统命令和特有的菜单命令 系统交给 AppUi处理
void CTestMultiViewAppView::HandleCommandL(TInt aCommand)
{
switch ( aCommand )
{
case EAknSoftkeyOk:
{
iEikonEnv->InfoMsg( _L("view1 ok") );
break;
}
case EAknSoftkeyBack:
{
AppUi()->HandleCommandL(EEikCmdExit);
break;
}
default:
{
AppUi()->HandleCommandL( aCommand );
break;
}
}
};
void CTestMultiViewAppView::HandleClientRectChange()
{
if ( iContainer )
{
iContainer->SetRect( ClientRect() );
}
};
//***********************视图的激活和反激活********************************
void CTestMultiViewAppView::DoActivateL(//主要功能是创建视图的容器对象,并把他压入栈中
const TVwsViewId& /*aPrevViewId*/,TUid /*aCustomMessageId*/,
const TDesC8& /*aCustomMessage*/)
{
if (!iContainer)//如果还没有初始化容器
{
iContainer = new (ELeave) CTestMultiViewAppContainer;
iContainer->SetMopParent(this);
iContainer->ConstructL( ClientRect() );//初始化容器
AppUi()->AddToStackL( *this, iContainer );//压入栈操作
}
};
void CTestMultiViewAppView::DoDeactivate()
{
if ( iContainer )
{
AppUi()->RemoveFromViewStack( *this, iContainer );//弹出栈来操作
}
delete iContainer;//删除堆中数据
iContainer = NULL;//指针设置为空
};
TestMultiViewAppView111和上面的实现是一样的 就是const TUid KView2Id = {2};
// INCLUDES
#include <aknview.h>
const TUid KView2Id = {2};
class CTestMultiViewAppContainer111;
/**
* CTestMultiViewAppView111
*
*/
class CTestMultiViewAppView111 : public CAknView
{
public:
void ConstructL();
~CTestMultiViewAppView111();
public:
TUid Id() const;
void HandleCommandL(TInt aCommand);
void HandleClientRectChange();
private:
void DoActivateL(const TVwsViewId& aPrevViewId,TUid aCustomMessageId,
const TDesC8& aCustomMessage);
void DoDeactivate();
private:
CTestMultiViewAppContainer111* iContainer;
};
#endif
实现如下:
void CTestMultiViewAppView111::ConstructL()
{
BaseConstructL( R_TESTMULTIVIEW_VIEW2 );
};
CTestMultiViewAppView111::~CTestMultiViewAppView111()
{
if ( iContainer )
{
AppUi()->RemoveFromViewStack( *this, iContainer );
}
delete iContainer;
};
TUid CTestMultiViewAppView111::Id() const
{
return KView2Id;
};
void CTestMultiViewAppView111::HandleCommandL(TInt aCommand)
{
switch ( aCommand )
{
case EAknSoftkeyOk:
{
iEikonEnv->InfoMsg( _L("view2 ok") );
break;
}
case EAknSoftkeyBack:
{
AppUi()->HandleCommandL(EEikCmdExit);
break;
}
default:
{
AppUi()->HandleCommandL( aCommand );
break;
}
}
};
void CTestMultiViewAppView111::HandleClientRectChange()
{
if ( iContainer )
{
iContainer->SetRect( ClientRect() );
}
};
//这个是窗口2的激活程序
void CTestMultiViewAppView111::DoActivateL(
const TVwsViewId& /*aPrevViewId*/,TUid /*aCustomMessageId*/,
const TDesC8& /*aCustomMessage*/)
{
if (!iContainer)
{
iContainer = new (ELeave) CTestMultiViewAppContainer111;
iContainer->SetMopParent(this);
iContainer->ConstructL( ClientRect() );
AppUi()->AddToStackL( *this, iContainer );
}
};
void CTestMultiViewAppView111::DoDeactivate()
{
if ( iContainer )
{
AppUi()->RemoveFromViewStack( *this, iContainer );
}
delete iContainer;
iContainer = NULL;
};
TestMultiViewAppContainer的定义和实现代码:
// INCLUDES
#include <coecntrl.h>
class CEikLabel; // for example labels
/**
* CTestMultiViewAppContainer
*
*/
class CTestMultiViewAppContainer : public CCoeControl, MCoeControlObserver
{
public:
void ConstructL(const TRect& aRect);
~CTestMultiViewAppContainer();
private:
void SizeChanged();
TInt CountComponentControls() const;
CCoeControl* ComponentControl(TInt aIndex) const;
void Draw(const TRect& aRect) const;
void HandleControlEventL(CCoeControl* aControl,TCoeEvent aEventType);
private:
CEikLabel* iLabel; // example label
CEikLabel* iToDoLabel; // example label
};
#endif // TESTMULTIVIEWAPPCONTAINER_H
实现如下:
#include <eiklabel.h> // for example label control
void CTestMultiViewAppContainer::ConstructL(const TRect& aRect)
{
CreateWindowL();
iLabel = new (ELeave) CEikLabel;
iLabel->SetContainerWindowL( *this );
iLabel->SetTextL( _L("Example View") );
iToDoLabel = new (ELeave) CEikLabel;
iToDoLabel->SetContainerWindowL( *this );
iToDoLabel->SetTextL( _L("Add Your controls/n here") );
SetRect(aRect);
ActivateL();
}
CTestMultiViewAppContainer::~CTestMultiViewAppContainer()
{
delete iLabel;
delete iToDoLabel;
}
void CTestMultiViewAppContainer::SizeChanged()
{
}
TInt CTestMultiViewAppContainer::CountComponentControls() const
{
return 2;
}
CCoeControl* CTestMultiViewAppContainer::ComponentControl(TInt aIndex) const
{
switch ( aIndex )
{
case 0:
return iLabel;
case 1:
return iToDoLabel;
default:
return NULL;
}
}
void CTestMultiViewAppContainer::Draw(const TRect& aRect) const
{
CWindowGc& gc = SystemGc();
//清空窗口上的内容
gc.SetPenStyle( CGraphicsContext::ENullPen );
gc.SetBrushColor( KRgbGray );
gc.SetBrushStyle( CGraphicsContext::ESolidBrush );
gc.DrawRect( aRect );
//绘制图形
gc.SetPenStyle(CGraphicsContext::ESolidPen);
gc.SetPenSize(TSize(3,3));
gc.SetPenColor(KRgbBlack);
gc.DrawEllipse(aRect);
gc.SetPenColor(KRgbBlue);
gc.SetPenStyle(CGraphicsContext::EDottedPen);
gc.SetPenSize(TSize(4,4));
gc.DrawLine(aRect.iTl,aRect.iBr);
}
//处理用户相应的按钮
void CTestMultiViewAppContainer::HandleControlEventL(
CCoeControl* aControl,TCoeEvent aEventType)
{
}
TestMultiViewAppContainer111的定义和实现代码:
// INCLUDES
#include <aknview.h>
const TUid KView2Id = {2};
class CTestMultiViewAppContainer111;
/**
* CTestMultiViewAppView111
*
*/
class CTestMultiViewAppView111 : public CAknView
{
public:
void ConstructL();
~CTestMultiViewAppView111();
public:
TUid Id() const;
void HandleCommandL(TInt aCommand);
void HandleClientRectChange();
private:
void DoActivateL(const TVwsViewId& aPrevViewId,TUid aCustomMessageId,
const TDesC8& aCustomMessage);
void DoDeactivate();
private:
CTestMultiViewAppContainer111* iContainer;
};
#endif
实现:
void CTestMultiViewAppView111::ConstructL()
{
BaseConstructL( R_TESTMULTIVIEW_VIEW2 );
};
CTestMultiViewAppView111::~CTestMultiViewAppView111()
{
if ( iContainer )
{
AppUi()->RemoveFromViewStack( *this, iContainer );
}
delete iContainer;
};
TUid CTestMultiViewAppView111::Id() const
{
return KView2Id;
};
void CTestMultiViewAppView111::HandleCommandL(TInt aCommand)
{
switch ( aCommand )
{
case EAknSoftkeyOk:
{
iEikonEnv->InfoMsg( _L("view2 ok") );
break;
}
case EAknSoftkeyBack:
{
AppUi()->HandleCommandL(EEikCmdExit);
break;
}
default:
{
AppUi()->HandleCommandL( aCommand );
break;
}
}
};
void CTestMultiViewAppView111::HandleClientRectChange()
{
if ( iContainer )
{
iContainer->SetRect( ClientRect() );
}
};
//这个是窗口2的激活程序
void CTestMultiViewAppView111::DoActivateL(
const TVwsViewId& /*aPrevViewId*/,TUid /*aCustomMessageId*/,
const TDesC8& /*aCustomMessage*/)
{
if (!iContainer)
{
iContainer = new (ELeave) CTestMultiViewAppContainer111;
iContainer->SetMopParent(this);
iContainer->ConstructL( ClientRect() );
AppUi()->AddToStackL( *this, iContainer );
}
};
void CTestMultiViewAppView111::DoDeactivate()
{
if ( iContainer )
{
AppUi()->RemoveFromViewStack( *this, iContainer );
}
delete iContainer;
iContainer = NULL;
};
这样的话他们的关键部分已经写的差不多了 下面看看资源文件的定义
TestMultiView.rss:
// 1 资源表示符
NAME TEST // 4 letter ID
// 2 资源定义需要的头文件
#include <eikon.rh>
#include <avkon.rsg>
#include <avkon.rh>
#include <appinfo.rh>
#include "TestMultiView.hrh"
#include "TestMultiView.rls"
// 3 定义资源的文件签名
RESOURCE RSS_SIGNATURE
{
}
// 4 默认的文档名称
RESOURCE TBUF r_default_document_name
{
buf="TEST";
}
// 5 定义应用程序默认的菜单和CBA栏按钮
//EIK_APP_INFO资源为应用程序指定各种标准控件 如状态面板等,
//通常会创建一个为状态面板指定新内容的资源,然后使用EIK_APP_INFO资源的status_pane字段引用它
RESOURCE EIK_APP_INFO
{
status_pane = r_testmultiview_status_pane;//定义状态面板的改变
}
/*
****************************************************************************
*第二部分 资源文件体
****************************************************************************
*/
// ----------------------------------------------------------------------------
// 本地的应用资源
// ----------------------------------------------------------------------------
//
RESOURCE LOCALISABLE_APP_INFO r_localisable_app_info
{
short_caption = qtn_caption_string;
caption_and_icon =
CAPTION_AND_ICON_INFO
{
caption = qtn_caption_string;
number_of_icons = 1;
icon_file = "//resource//apps//TestMultiView_0xEC2949F0.mif";
};
}
//----------------------------------------------------
// 状态面板资源定义
//----------------------------------------------------
RESOURCE STATUS_PANE_APP_MODEL r_testmultiview_status_pane
{
panes =
{
SPANE_PANE
{
type = EAknCtNaviPane; //子面板类型 这里是导航面板
id = EEikStatusPaneUidNavi; //导航面板的ID
resource = r_multiviewexam_navi_decorator; //导航面板的资源ID
}
};
}
RESOURCE NAVI_DECORATOR r_multiviewexam_navi_decorator //导航面板的资源ID
{
type = ENaviDecoratorControlTabGroup; //导航面板的类型
control = TAB_GROUP //导航面板的控制(使用的是标签组 tab_width代表标签组的类型)
{
tab_width = EAknTabWidthWithTwoTabs; // 面板的宽度
active = 0;
tabs = {
TAB
{
id = ETestMultiView1Tab; // from application hrh
txt = qtn_view1_tab; //"View1"
},
TAB
{
id = ETestMultiView2Tab;
txt = qtn_view2_tab; //"View2"
}
};
};
}
//----------------------------------------------------
// 菜单一
// AVKON_VIEW 视图资源关键字
// r_testmultiview_view1 视图资源ID
// 热键 菜单栏 CBA可以由用户定义 也可以使用整型的资源ID引用系统预先定义的资源
//----------------------------------------------------
//
RESOURCE AVKON_VIEW r_testmultiview_view1
{
hotkeys = r_testmultiview_hotkeys; //定义热键
menubar = r_testmultiview_menubar_view1; //定义菜单栏
cba = R_AVKON_SOFTKEYS_SELECTION_LIST; //定义CBA
}
RESOURCE MENU_BAR r_testmultiview_menubar_view1
{
titles =
{
MENU_TITLE { menu_pane = r_testmultiview_app_menu; txt = "MenuBarAPP1"; },
MENU_TITLE { menu_pane = r_testmultiview_view1_menu; txt = "MenuBarView1"; }
};
}
RESOURCE MENU_PANE r_testmultiview_view1_menu
{
items =
{
MENU_ITEM { command = ECommand1; txt = "MenuPaneview1"; }
};
}
//----------------------------------------------------
// 菜单二
//----------------------------------------------------
//
RESOURCE AVKON_VIEW r_testmultiview_view2
{
hotkeys = r_testmultiview_hotkeys;
menubar = r_testmultiview_menubar_view2;
cba = R_AVKON_SOFTKEYS_SELECTION_LIST;
}
RESOURCE MENU_BAR r_testmultiview_menubar_view2
{
titles =
{
MENU_TITLE { menu_pane = r_testmultiview_app_menu; txt = "App"; },
MENU_TITLE { menu_pane = r_testiview_view2_menu; txt = "View"; }
};
}
RESOURCE MENU_PANE r_testiview_view2_menu
{
items =
{
MENU_ITEM { command = ECommand1; txt = "MenuPaneview2"; }
};
}
//----------------------------------------------------
// 菜单一二共有的资源
//----------------------------------------------------
//
RESOURCE HOTKEYS r_testmultiview_hotkeys
{
control =
{
HOTKEY { command = EAknCmdExit; key = 'e'; }
};
}
RESOURCE MENU_PANE r_testmultiview_app_menu
{
items =
{
MENU_ITEM { command = ECommand1; txt = "MenuPaneApp1"; },
MENU_ITEM { command = EHelp; txt = "MenuPaneAppHelp1"; },
MENU_ITEM { command = EAbout; txt = "MenuPaneAppAbout1"; },
MENU_ITEM { command = EAknCmdExit; txt = "MenuPaneAppExit1"; }
};
}
//----------------------------------------------------
// 对话框的资源 1
//----------------------------------------------------
//
RESOURCE DIALOG r_about_query_dialog
{
flags = EGeneralQueryFlags | EEikDialogFlagNoBorder | EEikDialogFlagNoShadow;
buttons = R_AVKON_SOFTKEYS_OK_EMPTY;
items=
{
DLG_LINE
{
type = EAknCtPopupHeadingPane;
id = EAknMessageQueryHeaderId;
itemflags = EEikDlgItemNonFocusing;
control = AVKON_HEADING
{
};
},
DLG_LINE
{
type = EAknCtMessageQuery;
id = EAknMessageQueryContentId;
control = AVKON_MESSAGE_QUERY
{
};
}
};
}
//----------------------------------------------------
// 对话框的资源 2
//----------------------------------------------------
//
RESOURCE DIALOG r_privstmt_dialog_test {
flags = EAknDialogGenericQueryFlags;
buttons = R_AVKON_SOFTKEYS_YES_NO;
items = {
DLG_LINE {
type = EAknCtPopupHeadingPane;
id = EAknMessageQueryHeaderId;
itemflags = EEikDlgItemNonFocusing;
control = AVKON_HEADING {
label = qtn_privacy_statement_header;
};
},
DLG_LINE {
type = EAknCtMessageQuery;
id = EAknMessageQueryContentId;
control = AVKON_MESSAGE_QUERY {
};
}
};
}
//----------------------------------------------------
// 各种消息资源文件
//----------------------------------------------------
//
RESOURCE TBUF32 r_caption_string { buf=qtn_caption_string; }
RESOURCE TBUF32 r_about_dialog_title { buf=qtn_about_dialog_title; }
RESOURCE TBUF r_about_dialog_text { buf=qtn_about_dialog_text; }
RESOURCE TBUF r_command1_text { buf=qtn_command1_text; }
RESOURCE TBUF r_privacy_statement_filename_test { buf=qtn_privacy_statement_filename_test; }//"PrivacyStatement.txt"
// End of File
TestMultiView.hrh:
#define _UID3 0xEC2949F0
// TestMultiView enumerate command codes
enum TTestMultiViewIds
{
ECommand1 = 0x6001, // start value must not be 0
ECommand2,
EHelp,
EAbout
};
enum TTestMultiViewTabViewId
{
ETestMultiView1Tab= 1,
ETestMultiView2Tab
};
#endif // __TESTMULTIVIEW_HRH__
TestMultiView.rls:
// First item in "Options" menu pane
#define qtn_command1 "swb1 Message"
// Second item in "Options" menu pane
#define qtn_command2 "Message from file"
#define qtn_help "Help"
#define qtn_about "About"
// Third item in "Options" menu pane
#define qtn_exit "Exit"
// When user requests ECommand1 event, text below is shown.
#define qtn_command1_text "Hello World!"
#define qtn_loc_resource_file_1 "//resource//apps//TestMultiView_0xEC2949F0"
#define qtn_about_dialog_title "About"
#define qtn_about_dialog_text "TestMultiView Version 1.0.0/n/nAuthor: Possio_ShiWB/n/nSupport: support@mycompany.com/n/n(c) Your copyright notice"
#define qtn_view1_option_item "<TestView1 menu item>"
#define qtn_view2_option_item "<TestView2 menu item>"
#define qtn_privacy_statement_filename_test "PrivacyStatement.txt"
#define qtn_view1_tab "Test1"
#define qtn_view2_tab "Test2"
// End of File
TestMultiViewAppView,和TestMultiViewAppView111俩个类是俩个视图类他们都派生自CAKnView类,TestMultiViewAppUi创建并且拥有这俩个类,而且负责他们之间的切换