can we create controls by code?
| Fri, 2008-01-04 09:49 | |
|
|
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? 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... |






Forum posts: 65
Hai Rajesh,
ya,it is also possible in Symbian.Here is a sample of code to create Label.
In CSampleContainer.h
#define R_SAMPLECONTAINER_LABEL1public:
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
}
}
Forum posts: 1144
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
Forum posts: 65
Hai rbrunner,
ya, sorry Iam mistaken and also thanks for correction.
Forum posts: 140
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++
Forum posts: 140
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++
Forum posts: 1144
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
Forum posts: 140
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++
Forum posts: 65
Hai Rajesh,
Do u want to add a Bitmap to Container?
Forum posts: 140
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++
Forum posts: 65
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.
Forum posts: 1
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