1、库与头文件
aknskins.lib
#include <AknsDrawUtils.h
#include <AknsBasicBackgroundControlContext.h>
2、在视图或容器类头文件中添加
MAknsControlContext* iBackGround;
virtual TTypeUid::Ptr MopSupplyObject(TTypeUid aId);
3、在视图或容器类中添加实现
void ConstructL(const TRect& aRect)
{
CreateWindowL();
SetRect(aRect);
SetExtentToWholeScreen();
iBackGround = CAknsBasicBackgroundControlContext::NewL( KAknsIIDQsnBgScreen, Rect(), EFalse ); //添加这句
{
CreateWindowL();
SetRect(aRect);
SetExtentToWholeScreen();
iBackGround = CAknsBasicBackgroundControlContext::NewL( KAknsIIDQsnBgScreen, Rect(), EFalse ); //添加这句
ActivateL();
}
TTypeUid::Ptr CDiceAppView::MopSupplyObject(TTypeUid aId) //添加
{
if(aId.iUid == MAknsControlContext::ETypeId && iBackGround)
{
return MAknsControlContext::SupplyMopObject( aId, iBackGround);
}
{
return MAknsControlContext::SupplyMopObject( aId, iBackGround);
}
return CCoeControl::MopSupplyObject( aId );
}
void Draw(const TRect& /*aRect*/) const
{
CWindowGc& gc = SystemGc();
void Draw(const TRect& /*aRect*/) const
{
CWindowGc& gc = SystemGc();
TRect drawRect(Rect());
//gc.Clear(drawRect);
AknsDrawUtils::Background(AknsUtils::SkinInstance(),
AknsDrawUtils::ControlContext(this),this,gc,drawRect,KAknsDrawParamDefault); //添加
//gc.Clear(drawRect);
AknsDrawUtils::Background(AknsUtils::SkinInstance(),
AknsDrawUtils::ControlContext(this),this,gc,drawRect,KAknsDrawParamDefault); //添加
}
在析构函数添加删除
if(iBackGround)
delete iBackGround;
在析构函数添加删除
if(iBackGround)
delete iBackGround;
这样就可以实现使用系统皮肤了。