1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
class Timer
{
private:
static form frmTimer;//creates and show the form.. the cambalinho.h file is big.
UINT_PTR timerid=0;
unsigned int intInterval=0;
void TimerProc(HWND hwnd,UINT uMsg,UINT idEvent,DWORD dwTime)
{
//timerprocedure();
MessageBox(NULL,"hi", "hi", MB_OK);
}
static void CALLBACK _TimerProc(HWND hwnd,UINT uMsg,UINT idEvent,DWORD dwTime )
{
reinterpret_cast<Timer*>(idEvent)->TimerProc(hwnd,uMsg,idEvent,dwTime);
}
public:
std::function<void()> timerprocedure=NULL;
Timer()
{
frmTimer.Visible=false;
}
property<unsigned int> Interval
{
Get(unsigned int)
{
return intInterval;
},
Set(unsigned int uintInterval)
{
intInterval = uintInterval;
}
};
void Start()
{
if(timerid!=0)
KillTimer(WindowMain,timerid);//WindowMain is the handle that recives the 1st form handle(i create a form before these class)
timerid=SetTimer( WindowMain,reinterpret_cast<UINT_PTR>(this),(UINT)intInterval,&Timer::_TimerProc);
}
void Stop()
{
KillTimer(WindowMain,timerid);
timerid=0;
}
~Timer()
{
KillTimer(WindowMain,timerid);
}
};
|