如何动态添加删除菜单项?
参考下面代码:
void CDBMSexampleForm::DynInitMenuPaneL( TInt aResourceId,
CEikMenuPane* aMenuPane )
{
TBuf<64> des;
CAknForm::DynInitMenuPaneL( aResourceId, aMenuPane );
if ( aResourceId == R_AVKON_FORM_MENUPANE )
{
switch ( iType )
{
case EDBMSexampleCmdCreateRecord:
CEikonEnv::Static()->ReadResource( des, R_ADD_RECORD1 );
AddMenuItem( des, EDBMSexampleCmdSaveRecord, aMenuPane);
// Disable unnecessary menu items when "Edit" is selected
aMenuPane->SetItemDimmed( EAknFormCmdAdd, ETrue );
aMenuPane->SetItemDimmed( EAknFormCmdDelete, ETrue );
aMenuPane->SetItemDimmed( EAknFormCmdLabel, ETrue );
break;
case EDBMSexampleCmdDeleteRecord:
CEikonEnv::Static()->ReadResource( des, R_DELETE_RECORD1 );
AddMenuItem( des, EDBMSexampleCmdRemoveRecord, aMenuPane);
// Disable the edit menu item
aMenuPane->SetItemDimmed( EAknFormCmdEdit, ETrue );
break;
case EDBMSexampleCmdUpdateRecord:
CEikonEnv::Static()->ReadResource( des, R_UPDATE_RECORD1 );
AddMenuItem( des, EDBMSexampleCmdChangeRecord, aMenuPane);
// Disable unnecessary menu items when "Edit" is selected
aMenuPane->SetItemDimmed( EAknFormCmdAdd, ETrue );
aMenuPane->SetItemDimmed( EAknFormCmdDelete, ETrue );
aMenuPane->SetItemDimmed( EAknFormCmdLabel, ETrue );
break;
case EDBMSexampleCmdRetrieveRecord:
aMenuPane->SetItemDimmed( EAknFormCmdEdit, ETrue );
break;
}
}
}
/*
-----------------------------------------------------------------------------
CDBMSexampleForm::AddMenuItem( const TDesC &aDesC, TInt aCommandId,
CEikMenuPane* aMenuPane)
Description: Add one menu item
Comments:
Return values: N/A
-----------------------------------------------------------------------------
*/
void CDBMSexampleForm::AddMenuItem(const TDesC &aDesC, TInt aCommandId,
CEikMenuPane* aMenuPane)
{
CEikMenuPaneItem::SData itemData;
itemData.iText = aDesC;
itemData.iCommandId = aCommandId;
itemData.iFlags = 0;
itemData.iCascadeId = 0;
aMenuPane->AddMenuItemL( itemData );
}