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! :)