获取系统环境变化的事件通知

- symbian编程发布-yuelongr | 查看-67 | 发表时间-2009-11-10
适用平台:S60 3rd, S60 5th

symbian系统中有不少的事件通知,比如当线程死亡,区域改变或系统时间改变等系统环境变化的时候,我们就可以实时获取该的事件通知.

主要实现方法: 活动对象CEnvironmentChangeNotifier的应用.主要用回调函数TCallBack来完成事件的通知。

具体实现方案:

需要的头文件和链接库

#include <bacntf.h> // Link against bafl.lib

// NotifyChange is a static member function declared as follows:
// static TInt NotifyChange( TAny* aObject );
TCallBack envChangeCallback( NotifyChange, this );
iEnvNotifier = CEnvironmentChangeNotifier::NewL( CActive::EPriorityHigh, envChangeCallback );
// Issues a request for change events. When a change events occurs, the
// callback function is called. Note that after the first call to this
// function, the callback function is called immediately. iEnvNotifier->Start();

通过TChanges来获取事件通知

TInt CMyEnvironMentChangeNotifier::NotifyChange( TAny* aObject )
{
CMyEnvironMentChangeNotifier* thisPtr = static_cast<CMyEnvironMentChangeNotifier*>( aObject );
// Retrieve the changes in a bit field
const TInt changes( thisPtr->iEnvNotifier->Change() );
if( changes & EChangesLocale )
{
// System locale changed
}
if( changes & EChangesMidnightCrossover )
{
// Midnight crossover
}
if( changes & EChangesThreadDeath )
{
// Thread death
}
if( changes & EChangesPowerStatus )
{
// Power status changed
}
if( changes & EChangesSystemTime )
{
// System time changed
}
if( changes & EChangesFreeMemory )
{
// Free memory changed
}
if( changes & EChangesOutOfMemory )
{
// Out of memory
}
}

(来自:Forum Nokia Wiki)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值