×
Namespaces

Variants
Actions
(Difference between revisions)

Archived:Adding menu items dynamically using Symbian C++

From Nokia Developer Wiki
Jump to: navigation, search
Forum Nokia KB (Talk | contribs)
extkbeditor1 (Talk | contribs)
m
Line 5: Line 5:
 
[[Category:Technical Solution]]
 
[[Category:Technical Solution]]
  
{|border="2" cellspacing="0" cellpadding="4" width="100%"
+
{{KnowledgeBase
|
+
|id=TSS000712
====Subject:====
+
|platform=S60 1st Edition<br>S60 2nd Edition<br>S60 3rd Edition<br>Series 80 2nd Edition
|colspan = "2"|
+
|devices=
====Adding menu items dynamically====
+
|category=Symbian C<nowiki>++</nowiki>
|TSS000712
+
|subcategory=UI
 +
|creationdate=July 4, 2007
 +
|keywords=
 +
}}
  
|-
+
== Overview ==
|rowspan = "2"|
+
Adding menu items dynamically
====&nbsp;====
+
|Platform(s):
+
|colspan = "2"|Device(s), SW version(s):
+
  
|-
+
== Description ==
|S60 1st Edition<br>S60 2nd Edition<br>S60 3rd Edition<br>Series 80 2nd Edition
+
Items can be added to the menu dynamically, without making any changes to the resource file.
|colspan = "2"|&nbsp;
+
  
|-
+
== Solution ==
|
+
First, use an <nowiki>’</nowiki>empty<nowiki>’</nowiki> menu definition in the application resource file:<br>&nbsp;&nbsp;&nbsp;&nbsp;#include <nowiki><</nowiki>eikon.rh<nowiki>></nowiki><br>&nbsp;&nbsp;&nbsp;&nbsp;#include <nowiki><</nowiki>avkon.rh<nowiki>></nowiki><br>&nbsp;&nbsp;&nbsp;&nbsp;#include <nowiki><</nowiki>avkon.rsg<nowiki>></nowiki><br>&nbsp;&nbsp;&nbsp;&nbsp;#include "MyApp.hrh"<br>&nbsp;&nbsp;&nbsp;&nbsp;RESOURCE RSS_SIGNATURE<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>{</nowiki><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>}</nowiki><br>&nbsp;&nbsp;&nbsp;&nbsp;RESOURCE TBUF r_default_document_name<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>{</nowiki><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;buf="";<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>}</nowiki><br>&nbsp;&nbsp;&nbsp;&nbsp;RESOURCE EIK_APP_INFO<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>{</nowiki><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;menubar = r_myapp_menubar;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cba = R_AVKON_SOFTKEYS_OPTIONS_EXIT;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>}</nowiki><br>&nbsp;&nbsp;&nbsp;&nbsp;RESOURCE MENU_BAR r_myapp_menubar<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>{</nowiki><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;titles =<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>{</nowiki><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MENU_TITLE<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>{</nowiki><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;menu_pane = r_myapp_menu;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>}</nowiki><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>}</nowiki>;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>}</nowiki><br>&nbsp;&nbsp;&nbsp;&nbsp;RESOURCE MENU_PANE r_myapp_menu<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>{</nowiki><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;items =<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>{</nowiki><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Empty implementation of menu<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>}</nowiki>;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>}</nowiki><br>Then, override MEikMenuObserver::DynInitMenuPaneL() in the application UI class:<br>&nbsp;&nbsp;&nbsp;&nbsp;void CMyAppUi::DynInitMenuPaneL( TInt aResourceId, CEikMenuPane* aMenuPane )<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>{</nowiki><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if( aResourceId == R_MYAPP_MENU )<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>{</nowiki><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CEikMenuPaneItem::SData itemData;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;itemData.iText = _L("New menu item"); &nbsp;// Label text for the menu item<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;itemData.iCommandId = ECmdYourMenu; &nbsp;&nbsp;&nbsp;// Command ID for the menu item<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;itemData.iFlags = 0;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;itemData.iCascadeId = 0;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;aMenuPane-<nowiki>></nowiki>AddMenuItemL( itemData );<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>}</nowiki><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>}</nowiki><br>Note that there is no need to call DynInitMenuPaneL() directly as it will be called by the framework once the menu softkey is pressed.
====Category:====
+
|colspan = "3"|Symbian C<nowiki>++</nowiki>
+
  
|-
 
|
 
====Subcategory:====
 
|colspan = "3"|UI
 
 
|-
 
|
 
====Description:====
 
|colspan = "3"|'''Description:'''<br>Items can be added to the menu dynamically, without making any changes to the resource file.<br>'''Solution:'''<br>First, use an <nowiki>’</nowiki>empty<nowiki>’</nowiki> menu definition in the application resource file:<br>&nbsp;&nbsp;&nbsp;&nbsp;#include <nowiki><</nowiki>eikon.rh<nowiki>></nowiki><br>&nbsp;&nbsp;&nbsp;&nbsp;#include <nowiki><</nowiki>avkon.rh<nowiki>></nowiki><br>&nbsp;&nbsp;&nbsp;&nbsp;#include <nowiki><</nowiki>avkon.rsg<nowiki>></nowiki><br>&nbsp;&nbsp;&nbsp;&nbsp;#include "MyApp.hrh"<br>&nbsp;&nbsp;&nbsp;&nbsp;RESOURCE RSS_SIGNATURE<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>{</nowiki><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>}</nowiki><br>&nbsp;&nbsp;&nbsp;&nbsp;RESOURCE TBUF r_default_document_name<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>{</nowiki><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;buf="";<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>}</nowiki><br>&nbsp;&nbsp;&nbsp;&nbsp;RESOURCE EIK_APP_INFO<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>{</nowiki><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;menubar = r_myapp_menubar;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cba = R_AVKON_SOFTKEYS_OPTIONS_EXIT;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>}</nowiki><br>&nbs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p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>{</nowiki><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Empty implementation of menu<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>}</nowiki>;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>}</nowiki><br>Then, override MEikMenuObserver::DynInitMenuPaneL() in the application UI class:<br>&nbsp;&nbsp;&nbsp;&nbsp;void CMyAppUi::DynInitMenuPaneL( TInt aResourceId, CEikMenuPane* aMenuPane )<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>{</nowiki><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if( aResourceId == R_MYAPP_MENU )<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>{</nowiki><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CEikMenuPaneItem::SData itemData;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;itemData.iText = _L("New menu item"); &nbsp;// Label text for the menu item<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;itemData.iCommandId = ECmdYourMenu; &nbsp;&nbsp;&nbsp;// Command ID for the menu item<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;itemData.iFlags = 0;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;itemData.iCascadeId = 0;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;aMenuPane-<nowiki>></nowiki>AddMenuItemL( itemData );<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>}</nowiki><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>}</nowiki><br>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:====
 
|colspan = "3"|July 4, 2007
 
 
|-
 
|
 
====Last modified:====
 
|colspan = "3"|-
 
 
|-
 
 
[[Category:Symbian C++]][[Category:UI]][[Category:S60 1st Edition]] [[Category:S60 2nd Edition]][[Category:S60 3rd Edition]][[Category:Series 80 2nd Edition]]
 
[[Category:Symbian C++]][[Category:UI]][[Category:S60 1st Edition]] [[Category:S60 2nd Edition]][[Category:S60 3rd Edition]][[Category:Series 80 2nd Edition]]

Revision as of 17:45, 5 November 2008

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: (04 Jul 2007)
Last edited: extkbeditor1 (05 Nov 2008)

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.

86 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×