can we create controls by code?

Login to reply to this topic.
Fri, 2008-01-04 09:49
Joined: 2007-07-31
Forum posts: 140

Hi all,

I want to create a Text box or a label by code without writing in resource in Symbian C++, can i do that?
Because we can create Text box or Label or any control with the help of code in VC++(MFC).

if it is possible in Symbian C++ please paste relevent code...

Thanks in advance...

Brajesh...


Life is too short ! so do as many good things as you can do...
Brajesh Kumar...
Beginner in Symbian C++


Fri, 2008-01-04 10:30
Joined: 2007-10-16
Forum posts: 65
Re: can we create controls by code?

Hai Rajesh,
ya,it is also possible in Symbian.Here is a sample of code to create Label.

In CSampleContainer.h

#define  R_SAMPLECONTAINER_LABEL1
public:
CEikLabel* iLabel1;

In CSampleContainer.cpp

#include <eiklabel.h> //Header File For  Label
#include <barsread.h>

CSampleContainer::CSampleContainer()
        {
        iLabel1 = NULL;
        }
CSampleContainer::~CSampleContainer()
        {
        delete iLabel1;
        iLabel1 = NULL;
        }
CCoeControl* CSampleContainer::ComponentControl( TInt aIndex ) const
        {
        switch ( aIndex )
        {
        case ELabel1:
        return iLabel1;
        }
        return NULL;
        }
void CSampleContainer::LayoutControls()
        {
        iLabel1->SetExtent ( TPoint ( 5, 16 ), TSize ( 167, 30 ) );
                     }
void CSampleContainer::InitializeControlsL()
        {
        iLabel1 = new ( ELeave ) CEikLabel;
        iLabel1->SetContainerWindowL( *this );
                {
                TResourceReader reader;
                iEikonEnv->CreateResourceReaderLC( reader, R_SAMPLECONTAINER_LABEL1 );
                iLabel1->ConstructFromResourceL( reader );
                CleanupStack::PopAndDestroy(); // reader internal state
                                            }
                       }

Fri, 2008-01-04 11:00
Joined: 2005-11-20
Forum posts: 1144
Re: can we create controls by code?

Uhm, shilpa, I'm afraid that's exactly the wrong answer to the question. The question was how to create controls without resources...

Creating a control by code means to start like in shilpa's code:

iLabel1 = new ( ELeave ) CEikLabel;
iLabel1->SetContainerWindowL( *this );

but then set the text yourself instead of taking it from a resource file, with

_LIT(KLabelText,"Hello");
iLabel1->SetTextL(KLabelText);

Now, set any other properties, like the position (method 'SetPosition'), color, and so on, with the methods of the control that you find in the SDK documentation, and finally call ActivateL:

iLabel1->ActivateL();

For a complicated object like a listbox this can amount to quite some code, and if you forget to set some important property there can be rather weird errors, like controls that are impossible to activate, but otherwise there is almost complete freedom to do whatever you want, without any resources.


René Brunner

Fri, 2008-01-04 11:04
Joined: 2007-10-16
Forum posts: 65
Re: can we create controls by code?

Hai rbrunner,
ya, sorry Iam mistaken and also thanks for correction.

Fri, 2008-01-04 11:24
Joined: 2007-07-31
Forum posts: 140
Re: can we create controls by code?

Thanks Shilpa and rbrunner...

For providing idea to create controls without resource....

and shilpa can i know for which project u r working in Symbian and where?

Thanks...
Brajesh...


Life is too short ! so do as many good things as you can do...
Brajesh Kumar...
Beginner in Symbian C++

Fri, 2008-01-04 11:51
Joined: 2007-07-31
Forum posts: 140
Re: can we create controls by code?

Hi rburnner ,

but is it necessary to write the following functions....as given in the shilpa's code? I think thease functions will be needed when we would want to handle events....

CCoeControl* CSampleContainer::ComponentControl( TInt aIndex ) const

void CSampleContainer::LayoutControls()

void CSampleContainer::InitializeControlsL()

thanks...


Life is too short ! so do as many good things as you can do...
Brajesh Kumar...
Beginner in Symbian C++

Fri, 2008-01-04 13:18
Joined: 2005-11-20
Forum posts: 1144
Re: can we create controls by code?

It looks like shilpa's code is code for a so-called compound-control where you build a new control that has sub-controls in it.

But you probably do not have or need something like that, so if you have a simple view I think you can just put the code for control creation into the 'ContructL' method of the view.


René Brunner

Mon, 2008-01-07 11:00
Joined: 2007-07-31
Forum posts: 140
Re: can we create controls by code?

Can i draw an image in a dialog box in Symbian C++?


Life is too short ! so do as many good things as you can do...
Brajesh Kumar...
Beginner in Symbian C++

Wed, 2008-01-09 07:52
Joined: 2007-10-16
Forum posts: 65
Re: can we create controls by code?

Hai Rajesh,
Do u want to add a Bitmap to Container?

Wed, 2008-01-09 09:41
Joined: 2007-07-31
Forum posts: 140
Re: can we create controls by code?

hi shilpa my name is Brajesh

and i want to display an image on the dialog box control...

Brajesh...


Life is too short ! so do as many good things as you can do...
Brajesh Kumar...
Beginner in Symbian C++

Wed, 2008-01-09 11:05
Joined: 2007-10-16
Forum posts: 65
Re: can we create controls by code?

Hai Rajesh,
Pls go thru http://wiki.forum.nokia.com/index.php/How_to_draw_image_to_screen_directly ,I think it may be useful for u.

Thu, 2008-03-13 09:04
Joined: 2007-12-27
Forum posts: 1
Re: can we create controls by code?

Hi,
i tried this code in
void ClabelAppUi::HandleCommandL( TInt aCommand )

iLabel->SetContainerWindowL(*this);

The error message are
CCoeControl::SetContainerWindowL(const CCoeControl &)' (non-static)
CCoeControl::SetContainerWindowL(RBackedUpWindow &)' (non-static)
CCoeControl::SetContainerWindowL(RWindow &)' (non-static)
function call '[CEikLabel].SetContainerWindowL({lval} ClabelAppUi)' does not match

Kindly provide a solution

  • Login to reply to this topic.