如何用自己的图片作程序背景

参考资料:http://www.devdiv.net/viewthread.php?tid=2667&highlight=Grid

步骤:

1、*Ui.cpp源文件

在构造函数ConstructL()中:

BaseConstructL(EAknEnableSkin),让程序支持皮肤功能。

2、 MMP文件

START BITMAP bg.mbm
    HEADER
     SOURCEPATH ..icons
     SOURCE c12     bg.bmp
END

在项目的文件目录下新建一个icons文件夹,里面添加想要的背景图片,这里是bg.bmp;

当然,这个可以自己定制。

3、Container.h头文件

//  FORWARD DECLARATION
class  CAknsBasicBackgroundControlContext;

该类的头文件:AknsBasicBackgroundControlContext.h

库:AknSkins.lib

添加成员变量:

CAknsBasicBackgroundControlContext *  iBackGround;

4、Container.cpp源文件

添加头文件:

#include  < AknsBasicBackgroundControlContext.h >   // for CAknsBasicBackgroundControlContext
#include  < AknsDrawUtils.h >   // for AknsDrawUtils, CAknsItemDef and MAknskinInstance
#include  < AknUtils.h >   // for CompeleteWithAppPath()
#include  < bg.mbg >   // Background file

ConstructL()中添加:

iBackGround  =  CAknsBasicBackgroundControlContext::NewL( KAknsIIDQsnBgAreaMain, Rect(), EFalse );
MAknsSkinInstance
*  skin  =  AknsUtils::SkinInstance();
_LIT(KBitmapPath,
" bg.mbm " );
TFileName bitmapFile (KBitmapPath);
User::LeaveIfError(CompleteWithAppPath(bitmapFile));
CAknsItemDef
*  mainBgItemDef  =  AknsUtils::CreateBitmapItemDefL(KAknsIIDQsnBgAreaMain,bitmapFile,EMbmBgBg);
skin
-> SetLocalItemDefL( mainBgItemDef );

SizeChanged()中添加:

     if  ( iBackGround )
        
{
        iBackGround
->SetRect( Rect() );
        
if ( &Window() )
            iBackGround
->SetParentPos( PositionRelativeToScreen() );
        }

Draw() 中添加:

MAknsSkinInstance *  skin  =  AknsUtils::SkinInstance();
MAknsControlContext
*  cc  =  AknsDrawUtils::ControlContext(  this  );
AknsDrawUtils::Background( skin, cc, 
this , gc, aRect );

添加成员函数:

TTypeUid::Ptr CModel2ndContainer::MopSupplyObject(TTypeUid aId)
    
{
    
if(aId.iUid == MAknsControlContext::ETypeId && iBackGround)
        
{
        
return MAknsControlContext::SupplyMopObject( aId, iBackGround);
        }

    
return CCoeControl::MopSupplyObject( aId );
    }

别忘了先在头文件中声明,这个函数不知道在哪里被调用,但是必须要有。

析构函数添加:

delete iBackGround;

 

这样,程序编译、运行后应该就能看见自定义的背景了,HF!:)

 

评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值