效果图如下:
实现方法:
1、创建一个计时器,请将其打开
2、写计时器活动对象的回调函数,在回调函数中刷新屏幕
实现代码如下:
创建计时器活动对象并且打开定时器:
打开定时器代码:
回调函数Period()代码:
DoPeriodTask()函数代码:
刷屏函数UpdateDispaly()代码:
实现方法:
1、创建一个计时器,请将其打开
2、写计时器活动对象的回调函数,在回调函数中刷新屏幕
实现代码如下:
创建计时器活动对象并且打开定时器:
iPeriodicTimer
=
CPeriodic::NewL( CActive::EPriorityStandard );
//
创建活动对象
StartTimer(); // 打开定时器
StartTimer(); // 打开定时器
打开定时器代码:
1
if
(
!
iPeriodicTimer
->
IsActive() )
2 {
3 iPeriodicTimer->Start( 1, 1000000,
4 TCallBack( CFirewallContainerState::Period, this ) );
5 }
6
第3行中的1000000是将频率设置成1秒,单位是微秒
2 {
3 iPeriodicTimer->Start( 1, 1000000,
4 TCallBack( CFirewallContainerState::Period, this ) );
5 }
6
回调函数Period()代码:
1
TInt CFirewallContainerState::Period( TAny
*
aPtr)
2 {
3 ( static_cast < CFirewallContainerState *> ( aPtr ) ) -> DoPeriodTask();
4 return ETrue;
5 }
6
2 {
3 ( static_cast < CFirewallContainerState *> ( aPtr ) ) -> DoPeriodTask();
4 return ETrue;
5 }
6
DoPeriodTask()函数代码:
1
void
CFirewallContainerState::DoPeriodTask()
2 {
3
4 for ( TInt count = 0 ;count < iPointSet.Count();count ++ )
5 {
6 iPointSet[count] -> iX += 4 ;
7 }
8 if (iPointSet.Count() > 100 )
9 {
10 iPointSet.Reset() ;
11 }
12 TRect rect = Rect();
13 TInt y = GetRandY( rect.iBr.iY / 2 );
14 // 设置曲线的Y值的最大值
15 TPoint * p = new (ELeave)TPoint( 0 ,y);
16 iPointSet.Append(p);
17
18 // Update the screen
19 CWindowGc & gc = SystemGc();
20 gc.Activate( * DrawableWindow() );
21 UpdateDisplay();
22 gc.Deactivate();
23 }
24
2 {
3
4 for ( TInt count = 0 ;count < iPointSet.Count();count ++ )
5 {
6 iPointSet[count] -> iX += 4 ;
7 }
8 if (iPointSet.Count() > 100 )
9 {
10 iPointSet.Reset() ;
11 }
12 TRect rect = Rect();
13 TInt y = GetRandY( rect.iBr.iY / 2 );
14 // 设置曲线的Y值的最大值
15 TPoint * p = new (ELeave)TPoint( 0 ,y);
16 iPointSet.Append(p);
17
18 // Update the screen
19 CWindowGc & gc = SystemGc();
20 gc.Activate( * DrawableWindow() );
21 UpdateDisplay();
22 gc.Deactivate();
23 }
24
刷屏函数UpdateDispaly()代码:
void
CFirewallContainerState::UpdateDisplay()
const
{
CWindowGc& gc = SystemGc();
gc.Clear();
gc.SetPenStyle( CGraphicsContext::ENullPen );
gc.SetBrushColor( KRgbBlack );
gc.SetBrushStyle( CGraphicsContext::ESolidBrush );
TRect rect = TRect(Rect().iTl.iX, Rect().iTl.iY, Rect().iBr.iX, Rect().iBr.iY / 2);
gc.DrawRect(rect);
TSize PenSize(1,1);
gc.SetPenSize(PenSize);
gc.SetPenColor(KRgbGreen);
gc.SetPenStyle(CGraphicsContext::ESolidPen);
TInt RowCount = rect.iBr.iY / KRowWidth + 1;
TInt ColCount = rect.iBr.iX / KColWidth + 1;
//画横线
for(TInt count = 0; count < RowCount; count++)
{
TPoint p1(0,count*KRowWidth);
TPoint p2(rect.iBr.iX,count*KRowWidth);
gc.DrawLine(p1,p2);
}
//画最下面的横线
TPoint pBl(rect.iTl.iX,rect.iBr.iY);
TPoint pBr(rect.iBr.iX,rect.iBr.iY);
gc.DrawLine(pBl,pBr);
//画竖线
for(TInt count = 0; count < ColCount; count++)
{
TPoint p1(count*KColWidth,0);
TPoint p2(count*KColWidth,rect.iBr.iY);
gc.DrawLine(p1,p2);
}
//画右边的竖线
TPoint pTr(rect.iBr.iX, rect.iTl.iY);
gc.DrawLine(pTr, pBr);
//画曲线
gc.SetPenColor(KRgbYellow);
TInt count ;
for(count=0;count < iPointSet.Count()-1;count++)
{
gc.DrawLine(*iPointSet[count],*iPointSet[count+1]);
if (iPointSet.Count() == 100) count = 0 ;
}
//显示状态信息
//显示当前流量信息
gc.SetPenColor(KRgbBlack);
gc.UseFont( iCoeEnv->NormalFont() );
gc.SetPenColor(KRgbBlack);
TName msgCurrStorm ;
CEikonEnv::Static()->ReadResource(msgCurrStorm , R_STR_MSG_STATE_CURRENT_FLOW );
if (iPointSet.Count() > 0)
{
msgCurrStorm.AppendNum(Rect().iBr.iY / 2 - iPointSet[count]->iY) ;
msgCurrStorm.Append(_L(" KB")) ;
}
//将当前点的纵坐标作为模拟流量值显示
gc.DrawText( msgCurrStorm, TPoint(Rect().iTl.iX + 10,Rect().iBr.iY / 2 + 30)) ;
//判断是否设置了实时监控功能
TName msgRealtime ;
if (iUi->iSettingData->iIsRealtime)
{
CEikonEnv::Static()->ReadResource(msgRealtime , R_STR_MSG_STATE_REALTIME_ON );
}
else
{
CEikonEnv::Static()->ReadResource(msgRealtime , R_STR_MSG_STATE_REALTIME_OFF );
}
gc.DrawText( msgRealtime, TPoint(Rect().iTl.iX + 10,Rect().iBr.iY / 2 + 60)) ;
//无规则匹配时,默认的动作
TName msgDefaultaction ;
// gc.UseFont( iCoeEnv->NormalFont() );
switch (iUi->iSettingData->iDefaultAction)
{
case 0:
CEikonEnv::Static()->ReadResource(msgDefaultaction , R_STR_MSG_STATE_DEFAULTACTION_0 );
break ;
case 1:
CEikonEnv::Static()->ReadResource(msgDefaultaction , R_STR_MSG_STATE_DEFAULTACTION_1 );
break ;
case 2:
CEikonEnv::Static()->ReadResource(msgDefaultaction , R_STR_MSG_STATE_DEFAULTACTION_2 );
break ;
default:
break ;
}
gc.DrawText( msgDefaultaction, TPoint(Rect().iTl.iX + 10,Rect().iBr.iY / 2 + 90)) ;
}
{
CWindowGc& gc = SystemGc();
gc.Clear();
gc.SetPenStyle( CGraphicsContext::ENullPen );
gc.SetBrushColor( KRgbBlack );
gc.SetBrushStyle( CGraphicsContext::ESolidBrush );
TRect rect = TRect(Rect().iTl.iX, Rect().iTl.iY, Rect().iBr.iX, Rect().iBr.iY / 2);
gc.DrawRect(rect);
TSize PenSize(1,1);
gc.SetPenSize(PenSize);
gc.SetPenColor(KRgbGreen);
gc.SetPenStyle(CGraphicsContext::ESolidPen);
TInt RowCount = rect.iBr.iY / KRowWidth + 1;
TInt ColCount = rect.iBr.iX / KColWidth + 1;
//画横线
for(TInt count = 0; count < RowCount; count++)
{
TPoint p1(0,count*KRowWidth);
TPoint p2(rect.iBr.iX,count*KRowWidth);
gc.DrawLine(p1,p2);
}
//画最下面的横线
TPoint pBl(rect.iTl.iX,rect.iBr.iY);
TPoint pBr(rect.iBr.iX,rect.iBr.iY);
gc.DrawLine(pBl,pBr);
//画竖线
for(TInt count = 0; count < ColCount; count++)
{
TPoint p1(count*KColWidth,0);
TPoint p2(count*KColWidth,rect.iBr.iY);
gc.DrawLine(p1,p2);
}
//画右边的竖线
TPoint pTr(rect.iBr.iX, rect.iTl.iY);
gc.DrawLine(pTr, pBr);
//画曲线
gc.SetPenColor(KRgbYellow);
TInt count ;
for(count=0;count < iPointSet.Count()-1;count++)
{
gc.DrawLine(*iPointSet[count],*iPointSet[count+1]);
if (iPointSet.Count() == 100) count = 0 ;
}
//显示状态信息
//显示当前流量信息
gc.SetPenColor(KRgbBlack);
gc.UseFont( iCoeEnv->NormalFont() );
gc.SetPenColor(KRgbBlack);
TName msgCurrStorm ;
CEikonEnv::Static()->ReadResource(msgCurrStorm , R_STR_MSG_STATE_CURRENT_FLOW );
if (iPointSet.Count() > 0)
{
msgCurrStorm.AppendNum(Rect().iBr.iY / 2 - iPointSet[count]->iY) ;
msgCurrStorm.Append(_L(" KB")) ;
}
//将当前点的纵坐标作为模拟流量值显示
gc.DrawText( msgCurrStorm, TPoint(Rect().iTl.iX + 10,Rect().iBr.iY / 2 + 30)) ;
//判断是否设置了实时监控功能
TName msgRealtime ;
if (iUi->iSettingData->iIsRealtime)
{
CEikonEnv::Static()->ReadResource(msgRealtime , R_STR_MSG_STATE_REALTIME_ON );
}
else
{
CEikonEnv::Static()->ReadResource(msgRealtime , R_STR_MSG_STATE_REALTIME_OFF );
}
gc.DrawText( msgRealtime, TPoint(Rect().iTl.iX + 10,Rect().iBr.iY / 2 + 60)) ;
//无规则匹配时,默认的动作
TName msgDefaultaction ;
// gc.UseFont( iCoeEnv->NormalFont() );
switch (iUi->iSettingData->iDefaultAction)
{
case 0:
CEikonEnv::Static()->ReadResource(msgDefaultaction , R_STR_MSG_STATE_DEFAULTACTION_0 );
break ;
case 1:
CEikonEnv::Static()->ReadResource(msgDefaultaction , R_STR_MSG_STATE_DEFAULTACTION_1 );
break ;
case 2:
CEikonEnv::Static()->ReadResource(msgDefaultaction , R_STR_MSG_STATE_DEFAULTACTION_2 );
break ;
default:
break ;
}
gc.DrawText( msgDefaultaction, TPoint(Rect().iTl.iX + 10,Rect().iBr.iY / 2 + 90)) ;
}