Create the CAknButton object either dynamically from program code or from a resource structure. The constructed button can then be used as a component control of a compound control.
Use the resource structures AVKON_BUTTON , AVKON_BUTTON_STATE , and AVKON_BUTTON_STATE_EXTENSION for the button object (defined in the file eikon.rh ). The following example shows how to construct a button with the help of a button resource. The button is placed in a compound control (container) and it occupies the whole rectangle of the container. The container is set as the observer of the button.
Example: Button resource
RESOURCE AVKON_BUTTON r_myapp_button
{
flags = KAknButtonTextLeft;
states =
{
AVKON_BUTTON_STATE
{
txt = “Text”;
helptxt = “Help text”;
}
};
}
Example: Constructing button from resource
void CMyButtonContainer::CreateButtonL()
{
CAknButton* iAknButton = CAknButton::NewL();
iAknButton->ConstructFromResourceL(R_MYAPP_BUTTON);
iAknButton->SetContainerWindowL(*this);
iAknButton->SetRect(Rect());
iAknButton->SetObserver(this);
iAknButton->MakeVisible(ETrue);
iAknButton->ActivateL();
}
Example: Constructing button from program code
void CMyButtonContainer::CreateButtonL()
{
HBufC* buttonText = StringLoader::LoadLC( R_MYAPP_TEXT );
HBufC* helpText =
StringLoader::LoadLC( R_MYAPP_HELPTEXT );
CAknButton* iAknButton = CAknButton::NewL(
0, 0, 0, 0,
*buttonText, *helpText, KAknButtonTextLeft, 0);
CleanupStack::PopAndDestroy( 2 ); // helpText, buttonText
iAknButton->SetContainerWindowL(*this);
iAknButton->SetRect(Rect());
iAknButton->SetObserver(this);
iAknButton->MakeVisible(ETrue);
iAknButton->ActivateL();
}
Copyright ©2010 Nokia Corporation and/or its subsidiary(-ies).
All rights
reserved. Unless otherwise stated, these materials are provided under the terms of the Eclipse Public License
v1.0.