设置 Symbian 应用程序的背景图片
作者 Neot 写于 2011-12-08 | 49 次浏览(红色字体为添加的代码)
1. 环境
- Carbide C++ 2.7 (注:Carbide C++ 3.2 适于 S60 的开发,且没有 UI 编辑器)
- S60 3rd Edition FP1 SDK(FP2 没有测过)
- Windows 7(Windows xp 应该也不会有什么问题)
2. 新建 Symbian OS C++ Project
- 选择 S60/GUI Application with UI Designer,Next
- Project Name 处输入 Skinned,其它默认,Next
- 选择 S60_3rd_FP1,其它默认,Next
- Inital language 选择 Peoples Republic of Chinas Chinese(31),其它默认,Next
- S60 UI Design Selection 默认,Next
- Container Name and Type 默认,Finish
3. 在项目的 group/Skinned.mmp 文件里添加 Library 引用
LIBRARY aknskins.lib aknskinsrv.lib aknswallpaperutils.lib
4. 将图片添加到项目
5. 将图片添加到项目的资源库
START BITMAP Skinned.mbm
HEADER
TARGETPATH \resource\apps
SOURCEPATH ..\gfx
SOURCE c12,1 list_icon.bmp list_icon_mask.bmp
SOURCE c24 cba_bg.bmp main_bg.bmp END
enum TMbmSkinned { EMbmSkinnedList_icon, EMbmSkinnedList_icon_mask, EMbmSkinnedCba_bg, EMbmSkinnedMain_bg };
6.修改 inc/SkinnedContainer.h 文件
#include <AknsBasicBackgroundControlContext.h> //for CAknsBasicBackgroundControlContext#include <AknsDrawUtils.h> //for AknsDrawUtils, CAknsItemDef and MAknskinInstance#include <AknUtils.h> //for CompeleteWithAppPath()
class CSkinnedContainer : public CCoeControl
{
protected:
virtual TTypeUid::Ptr MopSupplyObject(TTypeUid aId);
private:
CAknsBasicBackgroundControlContext* iBackGround;
}
7.修改 src/SkinnedContainer.cpp 文件
// EMbmSkinnedMain_bg、EMbmSkinnedCba_bg
#include <Skinned.mbg>// bitmapFile
_LIT( KSkinnedFile, ”\\resource\\apps\\Skinned.mbm” );
//MopSupplyObjectmust provide a pointer to the control context, in this example theCAknsBasicBackgroundControlContextinstance.
TTypeUid::Ptr CSkinnedContainer::MopSupplyObject(TTypeUid aId){if(aId.iUid == MAknsControlContext::ETypeId && iBackGround){return MAknsControlContext::SupplyMopObject( aId, iBackGround);}return CCoeControl::MopSupplyObject( aId );}
// Initvoid CSkinnedContainer::ConstructL(const TRect& aRect,const CCoeControl* aParent,MEikCommandObserver* aCommandObserver ){if ( aParent == NULL ){CreateWindowL();}else{SetContainerWindowL( *aParent );}iFocusControl = NULL;iCommandObserver = aCommandObserver;InitializeControlsL();SetRect( aRect );iBackGround = CAknsBasicBackgroundControlContext::NewL( KAknsIIDQsnBgAreaMain, Rect(), EFalse );TFileName bitmapFile (KSkinnedFile);User::LeaveIfError(CompleteWithAppPath(bitmapFile));MAknsSkinInstance* skin = AknsUtils::SkinInstance();skin->SetLocalItemDefL(AknsUtils::CreateBitmapItemDefL(KAknsIIDQsnBgAreaMain, bitmapFile, EMbmSkinnedMain_bg));skin->SetLocalItemDefL(AknsUtils::CreateBitmapItemDefL(KAknsIIDQsnBgAreaControl, bitmapFile, EMbmSkinnedCba_bg));ActivateL();// [[[ begin generated region: do not modify [Post-ActivateL initializations]// ]]] end generated region [Post-ActivateL initializations]}
// Draw container contents.
void CSkinnedContainer::Draw( const TRect& aRect ) const{// [[[ begin generated region: do not modify [Generated Contents]CWindowGc& gc = SystemGc();gc.Clear( aRect );MAknsSkinInstance* skin = AknsUtils::SkinInstance();MAknsControlContext* cc = AknsDrawUtils::ControlContext( this );AknsDrawUtils::Background( skin, cc, this, gc, aRect );// ]]] end generated region [Generated Contents]}// Resizevoid CSkinnedContainer::SizeChanged()
{CCoeControl::SizeChanged();LayoutControls();// [[[ begin generated region: do not modify [Generated Contents]if ( iBackGround ){iBackGround->SetRect( Rect() );if ( &Window() )iBackGround->SetParentPos( PositionRelativeToScreen() );}// ]]] end generated region [Generated Contents]}
// Destroy child controlsCSkinnedContainer::~CSkinnedContainer(){// [[[ begin generated region: do not modify [Generated Contents]delete iBackGround;iBackGround = NULL;// ]]] end generated region [Generated Contents]}
//(如果有资源方面的错误,请做一次Clear,并重新编译)
8. 备注
skin->SetLocalItemDefL(AknsUtils::CreateBitmapItemDefL(KAknsIIDQsnBgAreaStatus, bitmapFile, EMbmSkinnedStatus_bg));
CEikStatusPane* statusp = iEikonEnv->AppUiFactory()->StatusPane();if(statusp){statusp->MakeVisible(EFalse);
}
[ 标签: symbian ]
[ 固定链接:http://blog.tanggaowei.com/2011/12/symbian-skin.html ]
| 分类 » 




