Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries. Thanks for all your past and future contributions.

Archived:Adding menu items dynamically using Symbian C++

From Wiki
Jump to: navigation, search

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}}.

Article Metadata
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
Created: User:Technical writer 2 (04 Jul 2007)
Last edited: hamishwillee (14 Jun 2012)


Adding menu items dynamically


Items can be added to the menu dynamically, without making any changes to the resource file.


First, use an 'empty' menu definition in the application resource file:
    #include <eikon.rh>
    #include <avkon.rh>
    #include <avkon.rsg>
    #include "MyApp.hrh"
    RESOURCE TBUF r_default_document_name
        menubar = r_myapp_menubar;
    RESOURCE MENU_BAR r_myapp_menubar
        titles =
                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.

This page was last modified on 14 June 2012, at 07:48.
63 page views in the last 30 days.