http://www.cnblogs.com/jason-jiang/archive/2006/12/03/580870.html
实现方法:
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

2

3

4

5

6

第3行中的1000000是将频率设置成1秒,单位是微秒
回调函数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()代码:
































































































