当在系统设置中设置了“实时监控”,此时手机画面的指示面板上应该出现一个图标,表明有程序在后台运行。 本文就是探讨怎样在S60指示面板上画图标。为了在电源面板附近显示图标,你必须要作相应的编码。
我写了一个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);
// by default setting the indicator icon to inactive SetIndicatorIconL(EIndicatorIconAppActive);
ActivateL(); }
注意,RWindowGroup需要W32std.h头文件,连接时需要添加Ws32.lib。
在构造函数中,调用另外一个函数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())); // if aRedraw == ETrue just draw the canvas again. if(aRedraw) { DrawNow(); } }
上面把指示面板需要显示的图标设置好了,但是必须要重载CCoeControl的Draw()函数来显示这个图标,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); }
最后在AppUi类的构造函数中添加如下两行代码:
iIndicatorIcon = CIndicatorIcon::NewL(); // The next line will set the icon to draw and it'll draw to the screen. iIndicatorIcon->SetIndicatorIconL(CIndicatorIcon::EIndicatorIconAppInactive, ETrue);
效果图如下:
Indicator icon when application is running in the foreground. |
|
Indicator icon when application is running in the background..
|
|
|
|
Indicator icon when application is running in the background with the task view.. |
|
|
你可以在这里下载示例程序的源代码:
 |