×
Namespaces

Variants
Actions
Revision as of 07:57, 14 March 2012 by debjit.roy (Talk | contribs)

Archived:Adding menu items dynamically using Symbian C++

From Nokia Developer Wiki
Jump to: navigation, search

Template:KBTS



Article Metadata
Compatibility
Platform(s): S60 1st Edition
S60 2nd Edition
S60 3rd Edition
Series 80 2nd Edition
S60 3rd Edition (initial release)
S60 2nd Edition (initial release)
S60 1st Edition
Article
Created: User:Technical writer 2 (04 Jul 2007)
Last edited: debjit.roy (14 Mar 2012)

Archived.pngArchived: This article is archived because it is not considered relevant for third-party developers creating commercial solutions today. If you think this article is still relevant, let us know by adding the template {{ReviewForRemovalFromArchive|user=~~~~|write your reason here}}.

Overview

Adding menu items dynamically

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.

100 page views in the last 30 days.
×