# Resources file

As it was already mentioned a Symbian application apart from the executable file have a resources file. The resources file contains binary records that will be used by the application.

There are two main reasons to keep some data apart from the executable file. The first is the code size - in the C++ code we would call several methods to set up different properties of an object. The compiler needs to generate code to call these methods. In a resource file we keep only the data that needs to be set up and call only one method to construct the object from resources.

Another reason is that it help to translate the program to another natural language - if we keep all the string that needs to be translated in the resources file we can give only the `*.rss` file for translation.

The resources file will be created from the text file `group\MyApp.rss` which have the following content:

    NAME HELL

    // you can include several type of files:
    //   *.rh  - resources definitions for the resource complier
    //   *.hrh - enums and constants - used by both C++ and the resource compiler
    //   *.rsg - IDs of resources in existing resources files.
    //           Can be used by both C++ and resources
    //   *.mbg - IDs of bitmaps in a MBM file
    //           Can be used by both C++ and resources
    #include <eikon.rh>
    #include <eikon.rsg>
    #include <avkon.rh>
    #include <avkon.rsg>

    #include "MyApp.hrh"

    // ---------------------------------------------------------
    //
    //    Define the resource file signature
    //    This resource should be empty.
    //
    // ---------------------------------------------------------
    //
    RESOURCE RSS_SIGNATURE { }

    // ---------------------------------------------------------
    //
    //    Default Document Name
    //
    // ---------------------------------------------------------
    //
    RESOURCE TBUF r_default_document_name { buf=""; }

    // ---------------------------------------------------------
    //
    //    Define default menu and CBA key.
    //
    // ---------------------------------------------------------
    //
    RESOURCE EIK_APP_INFO
        {
        menubar = r_myapp_menubar;
        cba = R_AVKON_SOFTKEYS_OPTIONS_EXIT;
        }

    // ---------------------------------------------------------
    //
    //   r_myapp_menubar
    //   Menubar for HelloWorld example
    //
    // ---------------------------------------------------------
    //
    RESOURCE MENU_BAR r_myapp_menubar
        {
        titles =
            {
            MENU_TITLE {menu_pane = r_myapp_menu;}
            };
        }

    // ---------------------------------------------------------
    //
    //   r_myapp_menu
    //   Menu for "Options"
    //
    // ---------------------------------------------------------
    //
    RESOURCE MENU_PANE r_myapp_menu
        {
        items =
            {
            MENU_ITEM {command = EMyAppCommand1;  txt = "Hello";},
            MENU_ITEM {command = EAknSoftkeyExit;   txt = "Exit";}
            };
        }

The first line containes the name of the resource file. It should have four letters and should be unique if you want to use more than one resource file in your application.

Then you include some files. The extensions are explained in the comment above. The `eikon.rh` and `avkon.rh` contains the standard resources types defnintions (e.g. `MENU_PANE`). The `eikon.rsg` and `avkon.rsg` contains the IDs of the resources in the standard resouces files `avkon.rss` and `eikon.rss`. We can use them to reference the standard resources (e.g. `R_AVKON_SOFTKEYS_OPTIONS_EXIT`).

You need to compile the application to create the binary file. By default the file will be called `MyApp.rsc`. However if you have configured different languages in your MMP file with e.g. `LANG 01 02` then two files will be created `MyApp.r01` and `MyApp.r02` containing different language versions of the resources.

Apart from the binary file(s) the compiler will create a `MyApp.rsg` file that will be created in the standard includes directory and will contain the IDs of our resources. E.g. the resource `r_myapp_menu` will have an ID `R_MYAPP_MENU`. The `*.rsg` can be included from both the C++ programs and other resources files.