×
Namespaces

Variants
Actions

如何为Series60绘制一个常驻顶端的提示图标

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata

兼容于
平台: S60 2nd Edition FP3, S60 3rd Edition

文章
翻译:
User:Davey 2
最后由 hamishwillee 在 30 May 2013 编辑

适用版本

S60 2nd Edition FP3, S60 3rd Edition

本文将简述如何在Series60中绘制一个始终处于前端的图标提示符,实际效果如上图所示,无论是处于待机界面,菜单界面或者切换时,一个音符的小图标始终都可见。这么做可以为一些应用程序起到提示的作用,比如在一个IM软件中,可以用它来提示有未读的消息等。 Home.PNG Menu.PNG Switch.PNG

1.如何构建 以下的构建过程基于我提供的示例程序: 构建一个CIndicatorIcon类来表示这个提示图标,它是从CCoeControl继承而来。它的第二阶段构造函数ConstructL()如下所示:

 void CIndicatorIcon::ConstructL()
       {
       iMyWindowGroup = RWindowGroup(iCoeEnv->WsSession());
       User::LeaveIfError(iMyWindowGroup.Construct((TUint32)&iMyWindowGroup));
       iMyWindowGroup.SetOrdinalPosition(0, ECoeWinPriorityAlwaysAtFront);
       iMyWindowGroup.EnableReceiptOfFocus(EFalse);
       CreateWindowL(&iMyWindowGroup);
       // 默认情况下把提示图标设置为inactive
       SetIndicatorIconL(EIndicatorIconAppActive);
       ActivateL();
       }

在ConstructL()中调用了SetIndicatorIconL()来设置图标,以下是该函数的具体实现:

 void CIndicatorIcon::SetIndicatorIconL(TIndicatorIcon aIndicatorIconType, TBool aRedraw)
       {
       switch(aIndicatorIconType)
               {
               case EIndicatorIconEmpty:
                       iIndicator = CEikonEnv::Static()->CreateBitmapL(KSysIconFile, EMbmAvkonQgn_prop_empty);
                       iIndicatorMask = CEikonEnv::Static()->CreateBitmapL(KSysIconFile, EMbmAvkonQgn_prop_empty_mask);
                       break;
               case EIndicatorIconAppActive:
                       iIndicator = CEikonEnv::Static()->CreateBitmapL(KSysIconFile, EMbmAvkonQgn_bt_connect_on);
                       iIndicatorMask = CEikonEnv::Static()->CreateBitmapL(KSysIconFile, EMbmAvkonQgn_bt_connect_on_mask);
                       break;
               case EIndicatorIconAppInactive:
                       iIndicator = CEikonEnv::Static()->CreateBitmapL(KSysIconFile, EMbmAvkonQgn_prop_bt_audio);
                       iIndicatorMask = CEikonEnv::Static()->CreateBitmapL(KSysIconFile, EMbmAvkonQgn_prop_bt_audio_mask);
                       break;
               default:
                       break;
               }
       SetRect(TRect(TPoint(KIndicatorPosX, KIndicatorPosY),iIndicator->SizeInPixels()));
      // 当aRedraw == ETrue时仅重绘
       if(aRedraw)
               {
               DrawNow();
               }
       }

同时必须重写CCoeControl的Draw()函数,在适当的位置绘制提示图标。

 void CIndicatorIcon::Draw(const TRect& aRect) const
       {
       CWindowGc& gc = SystemGc();
       gc.Clear();
       gc.SetBrushStyle(CGraphicsContext::ENullBrush);
       gc.BitBltMasked(TPoint(aRect.iTl.iX, aRect.iTl.iY), 
               iIndicator, 
               TRect(TPoint(0, 0), iIndicator->SizeInPixels()), 
               iIndicatorMask, 
               ETrue);
       }

到此你就完成了CIndicatorIcon类的构建。

2.如何使用 只要在你的程序的AppUi的ConstructL()中加入以下语句:

 iIndicatorIcon = CIndicatorIcon::NewL();
 // 以下该行设置需要绘制的图标
 iIndicatorIcon->SetIndicatorIconL(CIndicatorIcon::EIndicatorIconAppInactive, ETrue);

完成了,是的,就是这么简单。


例子请到如下地址下载:[1]


本文参考vin2ktalks的How to draw an Icon on the IndicatorPane of Series 60,在此表示感谢。


Best regards davey_2

This page was last modified on 30 May 2013, at 04:41.
110 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×