You can use the Symbian application creation Wizard to create a project with skin support. So that your application can easily use the system skin.
The creation method is as follows:
1. Open tools in the s60sdk directory in the Start menu and select Application Wizard to create an app.
2. On the second Wizard Page, you can see the options of add support for. Select the following skins and create again. You can get a project that supports skin.
If the skin function is not supported by an existing factory, you can manually add it. The procedure is as follows:
1) change the original baseconstructl () in the UI constructl function to baseconstructl (eaknenableskin );
2) Add header files to the iner
# Include <aknsbasicbackgroundcontrolcontext. h> // skin
3) Add a member variable in the iner and initialize it in constructl.
Add the member variable maknscontrolcontext * ibackground in. h; // For skins support
Constructl initialization in. cpp
Setrect (arect );
Ibackground = caknsbasicbackgroundcontrolcontext: newl (kaknsiidqsnbgareamain, rect (), efalse );
Put it after setrect !!!!!!! Otherwise, the skin cannot be seen.
4) container's
Draw (const trect & arect) const
{
Cwindowgc & GC = systemgc ();
// Todo: add your drawing code here
// Example code...
// Draw background
Maknsskininstance * Skin = aknsutils: skininstance ();
Maknscontrolcontext * Cc = aknsdrawutils: controlcontext (this );
Aknsdrawutils: background (skin, CC, this, GC, arect );
}
5) container's
Mopsupplyobject (ttypeuid aid)
{
If (AID. iuid = maknscontrolcontext: etypeid & ibackground)
{
Return maknscontrolcontext: supplymopobject (aid, ibackground );
}
Return ccoecontrol: mopsupplyobject (aid );
}
We can use the following method to obtain the color of the system skin:
Maknsskininstance * Skin = aknsutils: skininstance ();
Trgb color;
Aknsutils: getcachedcolor (skin, color, kaknsiidqsnscrollcolors, eaknsciqsniconcolorscg10 );
I made an enumeration color program:
Void testskincolor (taknsitemid aid, const tdesc & aname, const mobjectprovider * amop, cwindowgc & AGC)
...{
Maknsskininstance * Skin = aknsutils: skininstance ();
Maknscontrolcontext * Cc = aknsdrawutils: controlcontext (amop );
Trgb color;
Tint columnnum = 4;
Tint result = kerrnone;
Tint Index = 0;
While (result = kerrnone)
...{
Result = aknsutils: getcachedcolor (skin, color, aid, index );
If (result! = Kerrnone)
...{
Rdebug: Print (aname );
Rdebug: Print (_ L ("getcolorfaild, Index = % d"), index );
}
Else
...{
Rdebug: Print (aname );
Rdebug: Print (_ L ("[% d] color (% d, % d, % d)"), index, color. red (), color. green (), color. blue ());
}
Tint X, Y;
X = index % columnnum;
Y = index/columnnum;
Trect colorrect (tpoint (10 * x + * Y + 1), tsize (8 ));
AGC. setbrushcolor (color );
AGC. setbrushstyle (cgraphicscontext: esolidbrush );
AGC. drawroundrect (colorrect, tsize (2, 2 ));
Index ++;
}
}
This is the comparison of colors obtained under different skins:
First published in: http://blog.csdn.net/windcao/archive/2007/09/10/1779413.aspx