Tutorial 2 : First Dialog

Go through tutorial 1 first.

Now that you know how to print text on the screen, lets go to a little more complex application. We aregoing to add a menu to the application, how to handle commands in a little more detail, and finally create an alert dialog.

Here are the changes that it makes to the first tutorial.

  • Add the menu bar resource in the resource file to display the menu. The menubar attribute of EIK APP INFO is assigned a resource of type MENU BAR, which specifies the application’s default menu. Menu bar resources have one or more menu titles (type MENU TITLE)and each menu title points to a menu pane (type MENU PANE). The menu bar in the example, r_SecondApp_menubar, has a single menu title and this points to menu pane r_SecondApp_menu. Menu panes define the actual menu items (type MENU ITEM), whichthe user selects to invoke some operation in the application. r_SecondApp_menu defines a menu item labeled ‘Start’ that sends the command ESecondAppCommand to the GUI command handler code when the user selects it (so the code can display the Application’s dialog).
  • Now, we need to define the command codes used in the resource file. These are defined in the .hrh file. The file SecondApp.hrh contains the command values that the controls send (specified in the resource file) for the application code to handle. In this case we have only one, used when Start is selected: ``` enum TSecondAppIds { ESecondAppCommand = 1 }; ```
  • the menu item ‘Start’ is selected, the GUI framework invokes the HandleCommandL() method, passing it the command ESecondAppCommand (the command specified in the menu resource in the SecondApp.rss file). HandleCommandL() responds to this command by popping up an alert window with the message ‘Your First Dialog!’.We can use the iEikonEnv->AlertWin() function for the pop-up since this is a core GUI method available to all platforms. This function takes one arguement which is a descriptor.
    • Descriptors are classes that represent data buffers and allow you to safely access them. Symbian OS uses descriptors to store and manipulate strings (as opposed to NULL-terminated C strings), as well as to manage binary data. Descriptor classes, although containing many features, are optimized for minimal overhead, since they are designed to run on memory-constrained devices. There are multiple descriptor classes available in Symbian. You’ll need to use descriptors to call many of the Symbian OS API functions.

    • A String Literal(Descriptor) in Symbian is declared as:
      [cpp] _LIT(KMessage,"My First Dialog!");[/cpp]
      The LIT macro is called to take the string "My First Dialog!" and stores both the string and the string’s size in the descriptor literal KMessage.
Download Source code for this tutorial here. Go through tutorial 3 now.
Published 5 Jun 2011

I build mobile and web applications. Full Stack, Rails, React, Typescript, Kotlin, Swift
Pulkit Goyal on Twitter