Following code snippet shows how to create Label control in Symbian C++.
#include <eiklabel.h>
TInt CountComponentControls() const;
CCoeControl* ComponentControl(TInt aIndex) const;
void SetTextL(const TDesC& aText); // To change text(user-inputted)
private: // data
// ..
CEikLabel* iLabel;
void CLabelTestAppView::ConstructL( const TRect& aRect )
{
// Create a window for this application view
CreateWindowL();
_LIT(KTextHelloWorld, "hello world");
iLabel = new (ELeave) CEikLabel;
iLabel->SetContainerWindowL( *this );
iLabel->SetTextL(KTextHelloWorld);
// Set the windows size
SetRect( aRect );
// Activate the window, which makes it ready to be drawn
ActivateL();
}
CLabelTestAppView::~CLabelTestAppView()
{
delete iLabel;
}
void CLabelTestAppView::SizeChanged()
{
iLabel->SetExtent( TPoint(0,0), iLabel->MinimumSize());
}
TInt CLabelTestAppView::CountComponentControls() const
{
return 1;
}
CCoeControl* CLabelTestAppView::ComponentControl(TInt aIndex) const
{
switch ( aIndex )
{
case 0:
return iLabel;
default:
return NULL;
}
}
//Call this function to change value of Label
void CLabelTestAppView::SetTextL(const TDesC& aText)
{
iLabel->SetTextL(aText);
}
Note: Do not forget to add an entry for eikcoctl.lib in your .mmp file.
No related wiki articles found