您的位置:首页 > 编程语言 > C语言/C++

Symbian C++学习之——菜单基础

2009-04-08 19:56 423 查看
菜单是向用户展示列表的窗口,菜单由多个称作菜单项的行组成,每个菜单项含有一个文本标签。用户选择某个菜单项时调用相应的命令。

SimpleMenu实例如下图所示:



在SimpleMenu.rss资源文件中定义:

RESOURCE EIK_APP_INFO
{
menubar = r_simplemenu_menu_bar;
cba = R_AVKON_SOFTKEYS_OPTIONS_EXIT;
}

RESOURCE MENU_BAR r_simplemenu_menu_bar
{
titles =
{
MENU_TITLE
{
txt = ""; //Series 60中不使用用作菜单标题的文本
menu_pane = r_simplemenu_menu_pane;
}
};
}

RESOURCE MENU_PANE r_simplemenu_menu_pane
{
items =
{
MENU_ITEM
{
command = ESimpleMenuCmdNewGame;
txt = qtn_simplemenu_newgame;
cascade = r_simplemenu_submenu_pane; //定义子菜单
},
MENU_ITEM
{
command = EAknCmdExit;
txt = qtn_simplemenu_exit;
}
};
}

RESOURCE MENU_PANE r_simplemenu_submenu_pane
{
items =
{
MENU_ITEM
{
command = ESimpleMenuCmdGame1;
txt = qtn_simplemenu_submenu_game1;
},
MENU_ITEM
{
command = ESimpleMenuCmdGame2;
txt = qtn_simplemenu_submenu_game2;
}
};
}

在SimpleMenu.rls中定义字符串:

#define qtn_simplemenu_newgame "New Game"
#define qtn_simplemenu_exit "Exit"
#define qtn_simplemenu_submenu_game1 "Game 1"
#define qtn_simplemenu_submenu_game2 "Game 2"

在SimpleMenu.hrh文件中定义菜单命令枚举:

enum TSimpleMenuIds
{
//自定义枚举应该从0x6000开始,避免与系统命令冲突
ESimpleMenuCmdNewGame = 0x6001,
ESimpleMenuCmdGame1,
ESimpleMenuCmdGame2
};

处理菜单命令对于派生CAknAppUi或CAknView的类应使用HandleCommandL()方法,对于派生于CAknDialog的类则应该使用ProcessCommandL()。

在SimpleMenu实例中CSimpleMenuAppUi派生于CAknAppUi,所以重写了CSimpleMenuAppUi中的HandleCommandL()方法:

void CSimpleMenuAppUi::HandleCommandL(TInt aCommand)
{
switch (aCommand)
{
case EEikCmdExit:
case EAknSoftkeyExit:
Exit();
break;
case ESimpleMenuCmdNewGame:
//
break;
case ESimpleMenuCmdGame1:
//
break;
case ESimpleMenuCmdGame2:
//
break;
default:
Panic(ESimpleMenuUi);
break;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: