Код: Выделить всё
#include <process.h>
#include <windows.h>
#include <stdio.h>
#include <conio.h>
#define MINUTE(23)
#define HOUR (17)
#define RINGS (10)
HANDLE hTerminateEvent ;
VOID CALLBACK TimerAPCProc(LPVOID, DWORD, DWORD)
{
Beep(1000,500);
};
unsigned __stdcall ThreadFunc(void *)
{
HANDLE hDayTimer = CreateWaitableTimer(NULL,FALSE,NULL);
HANDLE hAlarmTimer = CreateWaitableTimer(NULL,FALSE,NULL);
HANDLE h[2];
h[0] = hTerminateEvent; h[1] = hDayTimer;
int iRingCount=0;
int iFlag;
DWORD dw;
LARGE_INTEGER liDueTime, liAllDay;
liDueTime.QuadPart=0;
liAllDay.QuadPart = 0xC9;
liAllDay.QuadPart=liAllDay.QuadPart << 32;
liAllDay.QuadPart |= 0x2A69C000;
SYSTEMTIME st;
GetLocalTime(&st);
iFlag = st.wHour > HOUR||st.wMinute>MINUTE;
st.wHour = HOUR;
st.wMinute = MINUTE;
st.wSecond =0;
FILETIME ft;
SystemTimeToFileTime( &st, &ft);
if (iFlag)
((LARGE_INTEGER *)&ft)->QuadPart =((LARGE_INTEGER *)&ft)->QuadPart +liAllDay.QuadPart ;
LocalFileTimeToFileTime(&ft,&ft);
SetWaitableTimer(hDayTimer, (LARGE_INTEGER *) &ft, 24*60*60000, 0, 0, 0);
do {
dw = WaitForMultipleObjectsEx(2,h,FALSE,INFINITE,TRUE);
if (dw == WAIT_OBJECT_0 +1)
{
SetWaitableTimer(hAlarmTimer, &liDueTime, 1000, TimerAPCProc, NULL, 0);
iRingCount=0;
}
if (dw == WAIT_IO_COMPLETION)
{
iRingCount++;
if (iRingCount==RINGS)
CancelWaitableTimer(hAlarmTimer);
}
}while (dw!= WAIT_OBJECT_0);
CancelWaitableTimer(hDayTimer);
CancelWaitableTimer(hAlarmTimer);
CloseHandle(hDayTimer);
CloseHandle(hAlarmTimer);
_endthreadex( 0 );
return 0;
};
int main(int argc, char* argv[])
{
hTerminateEvent = CreateEvent(NULL,FALSE,FALSE,NULL);
unsigned uThreadID;
HANDLE hThread;
hThread = (HANDLE)_beginthreadex( NULL, 0, &ThreadFunc, 0, 0,&uThreadID);
puts("Press any key to exit.");
getch();
SetEvent(hTerminateEvent);
WaitForSingleObject(hThread, INFINITE );
CloseHandle( hThread );
return 0;
}