//
class PowerNotificationTest
{
private:
TuPowerNotification<PowerNotificationTest> uPowerNotification;
public:
PowerNotificationTest() {}
~PowerNotificationTest() {}
void Init()
{
//初始化 TuPowerNotification
uPowerNotification.CombineElement(this, PowerNotificationTest::PowerNotify);
uPowerNotification.RequestPowerNotifications();
}
void PowerNotify(PPOWER_BROADCAST ppower_broadcast)
{
switch(ppower_broadcast->Message)
{
//取得 power status
case PBT_TRANSITION:
break;
case PBT_RESUME:
break;
case PBT_POWERSTATUSCHANGE:
break;
case PBT_POWERINFOCHANGE:
break;
}
}
// TuPowerNotification.h
template <typename T>
class TuPowerNotification : public CuPowerNotification
{
typedef void ( T::*POWER_NOTIFICATION_PROC)(PPOWER_BROADCAST ppower_broadcast);
POWER_NOTIFICATION_PROC m_fpPowerNotificationProc;
T *m_pElement;
public:
TuPowerNotification();
~TuPowerNotification();
void CombineElement(T *pElement, POWER_NOTIFICATION_PROC fpTimeOutProc);
virtual void OnPowerNotification(PPOWER_BROADCAST ppower_broadcast);
};
template <typename T>
TuPowerNotification<T>::TuPowerNotification()
:m_fpPowerNotificationProc(NULL)
,m_pElement(NULL)
{
}
template <typename T>
TuPowerNotification<T>::~TuPowerNotification()
{
}
template <typename T>
void TuPowerNotification<T>::OnPowerNotification(PPOWER_BROADCAST ppower_broadcast)
{
if(m_fpPowerNotificationProc)
(m_pElement->*m_fpPowerNotificationProc)(ppower_broadcast);
}
template <typename T>
void TuPowerNotification<T>::CombineElement(T *pElement, POWER_NOTIFICATION_PROC fpTimeOutProc)
{
m_pElement = pElement;
m_fpPowerNotificationProc = fpTimeOutProc;
}
2010年1月30日 星期六
TuPowerNotification -
訂閱:
張貼留言 (Atom)
在空閒時花點時間將配接器轉為樣版本,來是打算用的時後可以省點工,不過在次驗證了前輩們的話,用到在寫!改好樣版後,從此沒有用到過了!
回覆刪除