×
Namespaces

Variants
Actions
Revision as of 16:33, 24 August 2007 by Forum Nokia KB (Talk | contribs)

Archived:Adding menu items dynamically using Symbian C++

From Nokia Developer Wiki
Jump to: navigation, search

Template:KBTS

Subject:

Adding menu items dynamically

TSS000712

 

Platform(s): Device(s), SW version(s):
S60 1st Edition
S60 2nd Edition
S60 3rd Edition
Series 80 2nd Edition
 

Category:

Symbian C++

Subcategory:

UI

Description:

Description:
Items can be added to the menu dynamically, without making any changes to the resource file.
Solution:
First, use an ’empty’ menu definition in the application resource file:
    #include <eikon.rh>
    #include <avkon.rh>
    #include <avkon.rsg>
    #include "MyApp.hrh"
    RESOURCE RSS_SIGNATURE
        {
        }
    RESOURCE TBUF r_default_document_name
        {
        buf="";
        }
    RESOURCE EIK_APP_INFO
        {
        menubar = r_myapp_menubar;
        cba = R_AVKON_SOFTKEYS_OPTIONS_EXIT;
        }
    RESOURCE MENU_BAR r_myapp_menubar
        {
        titles =
            {
            MENU_TITLE
                {
                menu_pane = r_myapp_menu;
                }
            };
        }
    RESOURCE MENU_PANE r_myapp_menu
        {
        items =
            {
            // Empty implementation of menu
            };
        }
Then, override MEikMenuObserver::DynInitMenuPaneL() in the application UI class:
    void CMyAppUi::DynInitMenuPaneL( TInt aResourceId, CEikMenuPane* aMenuPane )
        {
        if( aResourceId == R_MYAPP_MENU )
            {
            CEikMenuPaneItem::SData itemData;
            itemData.iText = _L("New menu item");  // Label text for the menu item
            itemData.iCommandId = ECmdYourMenu;    // Command ID for the menu item
            itemData.iFlags = 0;
            itemData.iCascadeId = 0;
            aMenuPane->AddMenuItemL( itemData );
            }
        }
Note that there is no need to call DynInitMenuPaneL() directly as it will be called by the framework once the menu softkey is pressed.

Creation date:

July 4, 2007

Last modified:

-
68 page views in the last 30 days.
×