这个定时器为什么只能运行一次程序就退出了?
#include "stdafx.h"
#define ID_TIMER_CHECKTIME 1
INT CheckTime();
VOID CALLBACK TimerProc(
HWND hwnd, // handle to window
UINT uMsg, // WM_TIMER message
UINT_PTR idEvent, // timer identifier
DWORD dwTime // current system time
)
{
CheckTime();
}
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
::SetTimer(NULL,ID_TIMER_CHECKTIME,3000,(TIMERPROC)TimerProc);
MSG msg;
if (GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
KillTimer(NULL,ID_TIMER_CHECKTIME);
return 0;
}
// Check the system time
// if 0:00 - 5:00 then do something
INT CheckTime()
{
SYSTEMTIME st;
GetLocalTime(&st);
if (st.wHour >= 0 && st.wHour < 5)
{
MessageBox(NULL,"test","test",MB_OK);
return -1;
}
else
return 0;
}