⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 timer.cpp

📁 实现了无线传感器网络中的一个路由协议算法。
💻 CPP
字号:
// Timer.cpp: implementation of the CTimer class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "SimSensor.h"
#include "Timer.h"
#include "Msg.h"
#include "Node.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CTimer::CTimer()
{
   m_uID = NULL;
   m_Type = ONCE;
}

CTimer::~CTimer()
{

}

void CTimer::SetMyTimer(UINT uElapse,bool Type)
{   
	m_Type = Type;
	m_uID = (UINT)timeSetEvent(uElapse,0,(LPTIMECALLBACK)TimeProc,(DWORD)this,(Type?TIME_ONESHOT:TIME_PERIODIC)); 
	if (m_uID==NULL) TRACE("timeSetEvent fail!\n");
}


void CTimer::SendTimerMsg(int MsgType)
{
   	CMsg *pMsg ;
	pMsg = new CMsg;
	pMsg->Type = MsgType;               //collectdata Msg
	((CNode *)m_pNode)->MsgBuff.InsertMsg(pMsg);
}

void CTimer::Band(LPVOID pNode)
{
    m_pNode = pNode;
}

void CTimer::EndTimer()
{
    if (m_uID) {
	    timeKillEvent(m_uID);
	    m_uID = NULL;
	}
}

VOID CALLBACK CTimer::TimeProc(
  UINT uID,      
  UINT uMsg,     
  DWORD dwUser,  
  DWORD dw1,     
  DWORD dw2      
)
{
     CTimer *pTimer = (CTimer *)dwUser;
     if ( ONCE == pTimer->m_Type ) {
         //pTimer->SendTimerMsg (100);
         ::MessageBox(NULL,"Timer ONCE arrived!","hehe",MB_OK);
	 }else
 		 //pTimer->SendTimerMsg (101);
 		 ::MessageBox(NULL,"Timer CONTINUE arrived!","hehe",MB_OK);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -