谈谈SetMopParent函数

转自:http://www.newlc.com/Enable-Skin-support-in-your.html

 

Nokia has introduced skin support in S60 v2. For various reasons, including compatibility with S60 v1 and thus older devices, this support is not enabled by default: your application will display a not so original white background unless you code it differently.

A nice and user-friendly way to behave is to use the mobile theme skin as a background for your application. Unless very badly documented in the SDK so far, this is not that complex for most applications. Here is an example implementation.

Application UI

The impact in your application UI is quite limited. All you have to do is to enable skins when calling the AppUi base constructor:

// ConstructL is called by the application framework
void CSkinDemoAppUi::ConstructL()
{
BaseConstructL(EAknEnableSkin);
...
}

 

 

Application View or Containers

As you may have guessed, the main changes will be in your view and containers. The changes here may vary from simple to rather complex depending on what your are trying to achieve. Unfortunately, the Skin API is not very well documented and everything here is not always compatible in S60 3rd Edition... [1]

First, you need to create a specific context to hold the skin bitmap for your control. Do this by adding the following data member to your view/container class:

CAknsBasicBackgroundControlContext* iBgContext;

And initialize properly in the corresponding ConstructL, initialise a reference to the background bitmap:

#include <AknsDrawUtils.h>
#include <AknsBasicBackgroundControlContext.h>
...
void CSkinDemoAppView::ConstructL()
{
...
iBgContext = CAknsBasicBackgroundControlContext::NewL( KAknsIIDQsnBgAreaMain,aRect,ETrue);
...
}

 

 

Don't forget to call the corresponding destructor:

void CSkinDemoAppView::~CSkinDemoAppView()
{
...
delete iBgContext;
...
}

 

 

This context shall be passed to the child controls so that they can redisplay themselves correctly. This is done throgh MOP relationship and you then need to override the MopSupplyObject() primitive as follow:

TTypeUid::Ptr CSkinDemoAppView::MopSupplyObject(TTypeUid aId)
{
if (iBgContext )
{
   return MAknsControlContext::SupplyMopObject( aId, iBgContext );
}
return CCoeControl::MopSupplyObject(aId);
}

 

 

Each control Draw primitive shall now be updated to display the skin as background:

// Draw this application's view to the screen
void CSkinDemoAppView::Draw(const TRect& aRect) const
{
// Get the standard graphics context
CWindowGc& gc = SystemGc();
// Redraw the background using the default skin
MAknsSkinInstance* skin = AknsUtils::SkinInstance();
MAknsControlContext* cc = AknsDrawUtils::ControlContext( this );
AknsDrawUtils::Background( skin, cc, this, gc, aRect );
...
}

 

 

And finally:

void CSkinDemoAppView::SizeChanged()
{
if(iBgContext)
{
   iBgContext->SetRect(Rect());
                if ( &Window() )
                {
                        iBgContext->SetParentPos( PositionRelativeToScreen() );
                }
}
}

 

 

If your control contains a listbox, you can enable skin behind the items by calling:

iListBox->ItemDrawer()->ColumnData()->SetSkinEnabledL(ETrue)

MMP File

And finally, you need to link against the Avkon Skin libraries. Add the following line in your MMP file:

LIBRARY aknskins.lib aknskinsrv.lib

Download

Below you will find two samples project. One simple application created with the Codewarrior wizard without any skin support and its counterpart with skin support added.

SkinDemo.png
SkinDemo.sis
SkinDemo.sis
SkinDemo.zip
SkinDemo.zip

SkinDemo2.png
SkinDemo2.sis
SkinDemo2.sis
SkinDemo2.zip
SkinDemo2.zip

[1] But if you have the equivalent for 3rd edition... feel free to mail me so that I can update the page!

转载于:https://www.cnblogs.com/candyboy/archive/2010/04/13/1711375.html

项目名称:[精仿]360安全卫士-10.30更新(CSkin Demo) 界面库版本号:10.30 最新版本 下载内容: 精仿360安全卫士源码一份, 可引用至工具箱最新版CSkin.dll一份 实现功能: 1.发光标题。 2.直角边框和阴影。 3.360安全卫士主界面模仿。 4.多系统支持,不需要win8系统,即可实现win8风格的360。 5.自定义控件的美化使用。 界面库更新文档: CC2013-10.30 1.由于SkinForm名字太多人使用,界面库命名正式改为CSkin.dll,官网www.cskin.net。 2.SkinTabControl标签中添加菜单箭头,可点击展开菜单。 3.SkinTabControl添加标签关闭按钮。 4.修复部分中文乱码问题。 5.优化好友列表右键菜单。 6.将窗体自定义系统按钮改为集合模式,可添加无数个自定义系统按钮。自定义系统按钮事件中可以 e.参数 来判断。 7.增加360安全卫士-DEMO案例。 8.增加SkinAnimatorImg控件,用于支持位图动画的播放。如360的动态logo。 9.各种细节BUG优化。 CC2013-10.11 1.添加SkinTabControlEx,加入更加自定义的美化属性和动画效果。 2.添加SkinAnimator,通用动画控件。 3.添加Html编辑器控件 4.修复SkinButton图标和文本相对位置的BUG CC2013-9.26 1.优化好友列表CPU占用 2.好友列表加入好友登录平台属性:安卓 苹果 WEBQQ PC 3.优化标题绘制模式,新添标题绘制模式属性。 4.新添标题偏移度属性。 5.加入圆形进度条控件:ProgressIndicator。 CC2013-9.5.2 1.优化截图控件,截图工具栏加入新功能。 2.解决个人信息卡和天气窗体显示后不会消失的问题。 3.各种细节BUG优化。 CC2013-9.5.1 1.解决贴边左右隐藏的BUG。 2.解决窗体点击事件不能触发的问题。 3.优化SkinButton继承父容器背景色的代码。 4.解决SkinButton异常错误。 CC2013-9.3 1.好友列表右键菜单没反应问题。 2.新增美化控件SkinDatagridview。 3.密码软件盘回删不了文字问题。 4.双击窗体最大化,最大化后再双击恢复原大小,(win7)。 5.部分细节调优。 小编:下载不要分,DEMO教你如何熟练使用CSkin界面库美化自己的窗体。 友情链接: http://bbs.csdn.net/topics/390510544 (精仿QQ2013局域通讯) http://download.csdn.net/detail/lyx_520/5710799 (C#实现Win8窗体)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值