You Are Here:

Community: Wiki

This page was last modified on 8 October 2008, at 18:13.

CS000860 - Custom control: Construct from resource

From Forum Nokia Wiki



ID CS000860 Creation date March 25, 2008
Platform S60 3rd Edition, FP1 Tested on devices Nokia N95
Category Symbian C++ Subcategory UI


Keywords (APIs, classes, methods, functions): CCoeControl,TResourceReader

Overview

This code snippet shows how to create CCoeControl from a resource. This example extends the code snippet CS000859 - Custom control.

CMyControl::ConstructFromResourceL() initiates the control in the same way as the CMyControl::ConstructL() method, but the parameters are obtained from TResourceReader. The resource reader is a utility class that reads bytes from a resource file stream; therefore, reading must be in the same order and the data sizes must match those defined in the resource structure declaration.

MMP file

The following capabilities and libraries are required:

LIBRARY bafl.lib //TResourceReader

Header

Add a new function that is called when creating the class from the resource and add the BARSREAD.H include. The default constructor CMyControl() should be moved to public.

#include <BARSREAD.H>
 
public:
CMyControl();
void ConstructFromResourceL(TResourceReader& aReader);

Source

This code reads text for CEikLabel from the resource.

void CMyControl::ConstructFromResourceL(TResourceReader& aReader)
{
// No parent owner, so create an own window
CreateWindowL();
 
// Initialize component array
InitComponentArrayL();
 
// Create contained controls
iStatusText = new (ELeave) CEikLabel;
iStatusText->SetContainerWindowL(*this);
 
// Read label from resource
TPtrC label = aReader.ReadTPtrC16();
iStatusText->SetTextL(label);
 
// Store component to component array
Components().AppendLC(iStatusText);
CleanupStack::Pop(iStatusText);
 
// Set component rect to CMultiViewsAppUi::ClientRect()
CMultiViewsAppUi* appui = (static_cast<CMultiViewsAppUi*>(iEikonEnv->AppUi()));
appui->ClientRect();
if (appui)
{
SetRect(appui->ClientRect());
}
 
ActivateL();
}

CMyControl component resource customcontrol.rh file

Resource config parameters of the CMyControl component

STRUCT CUSTOMCONTROL
{
LTEXT txt;
}

Resource .rss file

Make the following changes to the Multiviews example application resource file multiviews.rss.

// New include that is our own component resource config
#include "customcontrol.rh"
 
// Defining resource for our component.
RESOURCE CUSTOMCONTROL r_custom_control
{
txt = STRING_r_custom_control;
}

STRING_r_custom_control is defined in multiviews.rls.


Creating component from resource

Create the resource reader, create the component via the default constuctor, and call ConstructFromResourceL()

// Creating control from resource
TResourceReader reader;
iEikonEnv->CreateResourceReaderLC(reader, R_CUSTOM_CONTROL);
iContainer2 = new (ELeave) CMyControl;
iContainer2->ConstructFromResourceL(reader);
iContainer2->SetRect(ClientRect());
CleanupStack::PopAndDestroy(); // reader

Postconditions

CMyControl is created by defined resource parameters.

See also

Custom Control Series:

Related Wiki Articles

No related wiki articles found

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia 
RDF Facets: qdcZidentifierQSxhttpE3aE2fE2fwikiE2eforumE2enokiaE2ecomE2findeE78E2ephpE2fPortingE5fBlackBerryE5fapplicationsE5fandE5fservicesE5ftoE5fS60E5fplatformX qdcZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qdcZtypeQUqfntypeZCommunityContentQ qdcZtypeQUqfntypeZE52esourceQ qdcZtypeQUqfntypeZWebpageQ qdcZtypeQUqfntypeZWikiContentQ qdcZtypeQUqmarsZManagedE52esourceQ qdcZtypeQUqwebZInformationE52esourceQ qdcZtypeQUqwebZPageQ qdcZtypeQUqwebZE52esourceQ qdcZtypeQUqrdfsZE52esourceQ qfnZtopicQUqfnTopicZseriesE5f60Q qfnZtypeQUqfntypeZCommunityContentQ qfnZtypeQUqfntypeZE52esourceQ qfnZtypeQUqfntypeZWebpageQ qfnZtypeQUqfntypeZWikiContentQ qfnZuserE5ftagQSxs60X qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX qrdfZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qrdfZtypeQUqfntypeZCommunityContentQ qrdfZtypeQUqfntypeZE52esourceQ qrdfZtypeQUqfntypeZWebpageQ qrdfZtypeQUqfntypeZWikiContentQ qrdfZtypeQUqmarsZManagedE52esourceQ qrdfZtypeQUqwebZInformationE52esourceQ qrdfZtypeQUqwebZPageQ qrdfZtypeQUqwebZE52esourceQ qrdfZtypeQUqrdfsZE52esourceQ
User Rating: qfnZuserE5FratingQNx1E2E0000X