zoukankan      html  css  js  c++  java
  • 如何用自己的图片作程序背景

    参考资料: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!:)

  • 相关阅读:
    HDU 5542 The Battle of Chibi (离散化+树状数组优化DP)
    UVaLive 7637 Balanced String (构造)
    ZOJ 3512 Financial Fraud (左偏树)
    HDU 1512 Monkey King (左偏树+并查集)
    POJ 2311 Cutting Game (博弈)
    POJ 2348 Euclid's Game (博弈)
    Gym 101142C CodeCoder vs TopForces (搜索)
    Gym
    Spring注解
    sql语句中的占位符?有什么作用
  • 原文地址:https://www.cnblogs.com/zziss/p/2176033.html
Copyright © 2011-2022 走看看