How to use your own images as a program background

Source: Internet
Author: User

Reference: http://www.devdiv.net/viewthread.php? Tid = 2667 & highlight = Grid

Steps:

1. * Ui. cpp source file

In ConstructL:

BaseConstructL (EAknEnableSkin) allows programs to support skin functions.

2. MMP File

Start bitmap bg. mbm
HEADER
SOURCEPATH... icons
SOURCE c12 bg.bmp
END

Create an icons folder under the project target file directory. The desired background image is bg.bmp;

Of course, this can be customized by yourself.

3. Container. h header file

// FORWARD DECLARATION
Class CAknsBasicBackgroundControlContext;

Header file of this class: AknsBasicBackgroundControlContext. h

Library: AknSkins. lib

Add member variables:

CAknsBasicBackgroundControlContext * iBackGround;

4. Container. cpp source file

Add header file:

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

Add the following to ConstructL:

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

Add the following to SizeChanged:

If (iBackGround)
...{
IBackGround-> SetRect (Rect ());
If (& Window ())
IBackGround-> SetParentPos (PositionRelativeToScreen ());
}

Add:

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

Add member functions:

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

Do not forget to declare in the header file that this function does not know where it is called, but it must be available.

Add destructor:

Delete iBackGround;

 

In this way, after the program is compiled and run, you should be able to see the custom background, HF! :)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.