Visual C++挖金子设计实现的源代码
源代码在线查看: myclock.h
#ifndef __MYCLOCK
#define __MYCLOCK
#include "stdio.h"
class MYCLOCK
{
public:
HWND hWnd;
HDC hDC;
int iNum;
int iNumShow;
int iElapse;
int iIsActive;
MYCLOCK()
{
iNum=0;
iIsActive=0;
iNumShow=0;
iElapse=100;
}
~MYCLOCK()
{
Destroy();
}
void Begin(HWND hw,int elapse,int timetotal)
{
if(iIsActive)
return;//已经启动了,直接返回
hWnd=hw;
iElapse=elapse;
SetTimer(hWnd,1,iElapse,NULL);
iNum=1000/iElapse;
iNumShow=timetotal;
iIsActive=1;
}
void Destroy()
{
if(iIsActive)
{
iIsActive=0;
KillTimer(hWnd,1);
}
}
void SetDC(HDC h)
{
hDC=h;
}
void Show()
{
char temp[20]={0};
sprintf(temp,"TIME: %d ",iNumShow);
TextOut(hDC,450,20,temp,strlen(temp));
}
int Dec()
{
iNum--;
if(iNum {
//过了一秒
iNum=1000/iElapse;
iNumShow--;
if(iNumShow {
iNumShow=0;
Destroy();
return 1;
}
}
return 0;
}
};
#endif