16,472
社区成员
发帖
与我相关
我的任务
分享
void CALLBACK MainWnd::myTimer( // 必须要静态或全局的
HWND hWnd, // handle of CWnd that called SetTimer
UINT nMsg, // WM_TIMER
UINT_PTR nIDEvent, // timer identification 指向this
DWORD dwTime // system time
)
{
((MainWnd*)nIDEvent)->autoScan();
}
int m_t1 = 0;
int m_t2 = 0;
void MainWnd::autoScan()
{
m_t2 = GetTickCount();
ASSERT( m_t2 - m_t1 > 1000 );
if( m_nTimer )
{
BOOL b = KillTimer( m_nTimer );
ASSERT( b );
m_nTimer = 0;
}
......
ASSERT( m_nTimer == 0 );
m_nTimer = SetTimer( (UINT_PTR)this, nIntervals[m_nAutoNum]*1000, myTimer );
ASSERT( m_nTimer == (UINT_PTR)this );
m_t1 = GetTickCount();
......
}
int m_t1 = 0;
int m_t2 = 0;
UINT m_nTimer=0;
//
void CALLBACK CDlgTimerDlg::myTimer(
HWND hWnd, // handle of CWnd that called SetTimer
UINT nMsg, // WM_TIMER
UINT nIDEvent, // timer identification 指向this
DWORD dwTime // system time
)
{
((CDlgTimerDlg*)nIDEvent)->autoScan();
}
void CDlgTimerDlg::autoScan()
{
m_t2 = GetTickCount();
if(m_t1==0)
{
m_t1=m_t2;
return;
}
if( m_t2 - m_t1 > 1000 )
{
afxDump << m_t2 - m_t1 << " Set\n";// ==="1014 Set"
if( m_nTimer )
{
KillTimer( m_nTimer );
m_nTimer = 0;
}
}
//
if(m_nTimer == 0 )
{ // nIntervals[m_nAutoNum]*
m_nTimer = SetTimer((UINT)this, 1000, myTimer );
ASSERT( m_nTimer == (UINT)this );
}
m_t1 = GetTickCount();
}
afxDump << m_t2 - m_t1 << " Set\n";// ==="1014 Set"
void CDlgTimerDlg::autoScan()
{
m_t2 = GetTickCount();
if( m_t2 - m_t1 > 1000 )
{
afxDump << m_t2 - m_t1 << " Set\n";// ==="1014 Set"
if( m_nTimer )
{
KillTimer( m_nTimer );
m_nTimer = 0;
}
}
//
if(m_nTimer == 0 )
{ // nIntervals[m_nAutoNum]*
m_nTimer = SetTimer((UINT)this, 1000, myTimer );
ASSERT( m_nTimer == (UINT)this );
}
//
m_t1 = GetTickCount();
// afxDump << m_t2 - m_t1 << " \n";// ===0
}