生活随笔
收集整理的這篇文章主要介紹了
mfc实现秒表小项目
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
項目截圖:
先設計一個Timer類,用于計時,放在頭文件Timer.h里面class Timer
{
public:
Timer();~Timer();Timer
operator++(){s++;
if (s >=
60){s -=
60;m++;
if (m >=
60){m -=
60;h++;
if (h >=
60){h -=
60;}}}
return *
this;}Timer
operator++(
int){Timer old = *
this;++(*
this);
return old;}
int getH()
const{
return h;}
int getM()
const{
return m;}
int getS()
const{
return s;}
private:
int h, m, s;
};Timer::Timer()
{h = m = s =
0;
}Timer::~Timer()
{
}
DWORD WINAPI clock1_proc(LPVOID lparam)
{Timer t;CString s;
while (
true){t++;Sleep(
1000);s.Format(_T(
"%02d:%02d:%02d"), t.getH(), t.getM(), t.getS());((CStatic*)lparam)->SetWindowTextW(s);}
}
void CClockDlg::OnBnClickedStart()
{
if (hClock1){ResumeThread(hClock1);}
else{hClock1 = CreateThread(
0,
0, clock1_proc, &
this->hClock1Ctl,
0, NULL);}}
void CClockDlg::OnBnClickedPause()
{
if (hClock1){SuspendThread(hClock1);}
}
void CClockDlg::OnBnClickedReset()
{
if (hClock1){TerminateThread(hClock1,
0);hClock1Ctl.SetWindowTextW(_T(
"00:00:00"));hClock1 = NULL;}
}
源碼下載:https://pan.baidu.com/s/134Qn9pBb0Hq32h7A_cQqzg
總結
以上是生活随笔為你收集整理的mfc实现秒表小项目的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。