最近在"体验"一个加密锁的操作,既然是加密锁肯定要不断访问锁上信息,"百度"and"Google"了解到一些思路,使用Timer控件,另外是采用时间消息响应机制使用的SetTimer函数,在VC6.0中Add to Project没有找到Timer控件,“百度”,发现vc没有Timer控件,只有使用SetTimer()了,
Google了几篇文章,有简单的介绍,不详细。都是没有源代码(呵呵,本人比较笨,有代码才能明白,万一不明白就“照葫芦画瓢”),我现在清楚了贴出代码方便需要的人。
/Files/Lee7/Time.rar (可以下载代码参考)

void CTimeDlg::On_start()


{
// TODO: Add your control notification handler code here
SetTimer(1,1000,NULL);
}

void CTimeDlg::OnTimer(UINT nIDEvent)


{
// TODO: Add your message handler code here and/or call default
UpdateData(TRUE);

m_num+=1;
UpdateData(FALSE);
CDialog::OnTimer(nIDEvent);
}


void CTimeDlg::On_stop()


{
// TODO: Add your control notification handler code here
KillTimer(1);
}

百度答案如下(和我这个基本一致):
Windows API
SetTimer(HWND,UNIT,UINT,TIMERPROC);
参数意义:
1.记时器所在窗口句柄
2.序号
3.记时周期
4.记时器响应函数
CWnd类的
CWnd::SetTimer (UINT SetTimer,UINT nIDEvent, UINT nElapse, void (CALLBACK EXPORT* lpfnTimer)( HWND, UINT, UINT, DWORD) );
CWnd类的用例:
1
void CMainFrame::OnStartTimer()
2

{
3
m_nTimer = SetTimer(1, 2000, 0);
4
}
5
6
void CMainFrame::OnStopTimer()
7

{
8
KillTimer(m_nTimer);
9
}
10
11
void CMainFrame::OnTimer(UINT nIDEvent)
12

{
13
MessageBeep(0xFFFFFFFF); // Beep
14
// Call base class handler.
15
CMDIFrameWnd::OnTimer(nIDEvent);
16
}