
/*******************************************************\
{                                                       }
{       Microsoft Visual C++ Version 4.X                }
{       Alarm Clock 1.0                                 }
{                                                       }
{       Copyright (C) 1996, CAT Computing Center (R).   }
{                                                       }
\*******************************************************/

#define STRICT
#include <Windows.h>
#include <Windowsx.h>
#include <mmsystem.h>
#include <tchar.h>
#include <stdio.h>
#include <stdarg.h>
#include "Resource.h"
#include "Alarm.h"

#define CY_LINE			3

#define CX_ITEM			7
#define CY_ITEM			25

#define CX_SEGMENT		26
#define CY_SEGMENT		CY_ITEM * 2 + CY_LINE

static WNDPROC oldWndPros = NULL;
static SYSTEMTIME s_SysTime;

static DWORD s_dwIDS[7] = {IDS_DAY0, IDS_DAY1, IDS_DAY2, IDS_DAY3, IDS_DAY4, IDS_DAY5, IDS_DAY6};
static TCHAR s_szDayList[7][3];

static TCHAR s_szAlarm0[11] = _T("");
static TCHAR s_szAlarm1[11] = _T("");
static TCHAR s_szWave[] = _T("WAVE");
static HBRUSH s_hLightBrush = NULL;
static HBRUSH s_hDarkBrush = NULL;

///////////////////////////////////////////////////////////////////////////////

DWORD IsMultimedia()
{
	DWORD dwRes = 0;

	dwRes |= waveOutGetNumDevs() ? AC_WAVE : 0;
	dwRes |= midiOutGetNumDevs() ? AC_MIDI : 0;

	return dwRes;
}

BOOL WINAPI ThreadTime(UINT uCount)
{
	if(!(IsMultimedia() & AC_WAVE))
	{
/*		if(g_AppOption.AlarmSet.uClockNot != 3)
		{
			ReportBox(IDS_NO_DEVICE, MB_OK | MB_ICONSTOP);
			return FALSE;
		}*/
		g_AppData.fStopSound = FALSE;
		for(UINT i = 0; i < uCount; i++)
		{
			MessageBeep(0xFFFFFFFF);
			DWORD dwStart = GetTickCount();
			dwStart += 500;
			while(dwStart > GetTickCount());
			if(g_AppData.fStopSound)
				break;
		}
		g_AppData.fStopSound = FALSE;
		return TRUE;
	}

	if(/*g_AppOption.AlarmSet.szFileName3[0] && */(g_AppOption.AlarmSet.uClockNot != 3))
	{
		if(!sndPlaySound(g_AppOption.AlarmSet.szFileName3, SND_ASYNC))
		{
			ReportBox(IDS_PS_FAILED, MB_OK | MB_ICONSTOP);
			return FALSE;
		}
		return TRUE;
	}

	HANDLE hWave = FindResource(g_AppData.hInstance, MAKEINTRESOURCE(IDR_WAVE2), s_szWave);
	if(hWave)
	{
		HANDLE hRes = LoadResource(g_AppData.hInstance, (HRSRC)hWave);	
		if(hRes)
		{
			LPCSTR lpRes = (LPCSTR)LockResource(hRes);
			if(lpRes)
			{
				g_AppData.fStopSound = FALSE;
				for(UINT i = 0; i < uCount; i++)
				{
					if(!sndPlaySound(lpRes, SND_SYNC | SND_MEMORY))
					{
						ReportBox(IDS_PS_FAILED, MB_OK | MB_ICONSTOP);
						break;
					}
					DWORD dwStart = GetTickCount();
					dwStart += 500;
					while(dwStart > GetTickCount());
					if(g_AppData.fStopSound)
						break;
				}
				g_AppData.fStopSound = FALSE;
				UnlockResource(lpRes);
			}
			FreeResource(hRes);
		}
	}
	return TRUE;
}

void TimeSound(UINT uCount)
{
	DWORD dwID;
	HANDLE hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)ThreadTime, (LPVOID)uCount, 0, &dwID);
	if(hThread)
		CloseHandle(hThread);
}

void DrawItem(HDC hDC, int nX, int nY, BOOL fVertical, BOOL fDark = FALSE)
{
	HBRUSH hOldBrush;
	if(fDark)
		hOldBrush = (HBRUSH)SelectObject(hDC, s_hDarkBrush);
	else
		hOldBrush = (HBRUSH)SelectObject(hDC, s_hLightBrush);

	if(fVertical)
		RoundRect(hDC, nX, nY, nX + CX_ITEM, nY + CY_ITEM, 7, 7);
	else
		RoundRect(hDC, nX + 7, nY - 3, nX + CY_ITEM + 1, nY + CX_ITEM - 3, 7, 7);
	SelectObject(hDC, hOldBrush);
}

void DrawSegment(HDC hDC, int nX, int nY, int nDigital = -1)
{
	BOOL fDark0 = FALSE, fDark1 = FALSE, fDark2 = FALSE, fDark3 = FALSE,
		fDark4 = FALSE, fDark5 = FALSE, fDark6 = FALSE;

	switch(nDigital)
	{
		case 0:
		{
			fDark0 = TRUE; fDark1 = TRUE; fDark2 = TRUE; fDark3 = TRUE; fDark4 = TRUE; fDark6 = TRUE;
			break;
		}

		case 1:
		{
			fDark1 = TRUE; fDark3 = TRUE; 
			break;
		}

		case 2:
		{
			fDark1 = TRUE; fDark2 = TRUE; fDark4 = TRUE; fDark5 = TRUE;	fDark6 = TRUE;
			break;
		}

		case 3:
		{
			fDark1 = TRUE; fDark3 = TRUE; fDark4 = TRUE; fDark5 = TRUE; fDark6 = TRUE;
			break;
		}

		case 4:
		{
			fDark0 = TRUE; fDark1 = TRUE; fDark3 = TRUE; fDark5 = TRUE;
			break;
		}

		case 5:
		{
			fDark0 = TRUE; fDark3 = TRUE; fDark4 = TRUE; fDark5 = TRUE; fDark6 = TRUE;
			break;
		}

		case 6:
		{
			fDark0 = TRUE; fDark2 = TRUE; fDark3 = TRUE; fDark4 = TRUE; fDark5 = TRUE; fDark6 = TRUE;
			break;
		}

		case 7:
		{
			fDark1 = TRUE; fDark3 = TRUE; fDark4 = TRUE;
			break;
		}

		case 8:
		{
			fDark0 = TRUE; fDark1 = TRUE; fDark2 = TRUE; fDark3 = TRUE; fDark4 = TRUE; fDark5 = TRUE; fDark6 = TRUE;
			break;
		}

		case 9:
		{
			fDark0 = TRUE; fDark1 = TRUE; fDark3 = TRUE; fDark4 = TRUE; fDark5 = TRUE; fDark6 = TRUE;
			break;
		}
	}

	DrawItem(hDC, nX, nY, TRUE, fDark0);
	DrawItem(hDC, nX, nY + CY_ITEM + CY_LINE, TRUE, fDark2);

	DrawItem(hDC, nX + CX_SEGMENT, nY, TRUE, fDark1);
	DrawItem(hDC, nX + CX_SEGMENT, nY + CY_ITEM + CY_LINE, TRUE, fDark3);

	DrawItem(hDC, nX, nY, FALSE, fDark4);
	DrawItem(hDC, nX, nY + CY_ITEM + 1, FALSE, fDark5);
	DrawItem(hDC, nX, nY + CY_SEGMENT, FALSE, fDark6);

}

void DrawSeparator(HDC hDC, int nX, int nY, BOOL fDark)
{
	HBRUSH hOldBrush;
	if(fDark)
		hOldBrush = (HBRUSH)SelectObject(hDC, s_hDarkBrush);
	else
		hOldBrush = (HBRUSH)SelectObject(hDC, s_hLightBrush);
	
	Ellipse(hDC, nX, nY + CY_ITEM - 14, nX + 7, nY + CY_ITEM - 14 + 7);
	Ellipse(hDC, nX, nY + CY_ITEM + 10, nX + 7, nY + CY_ITEM + 10 + 7);
	SelectObject(hDC, hOldBrush);
}

void DrawWeekDays(HDC hDC, int nX, int nY, int nDay)
{
	for(int i = 0; i < 7; i++)
	{
		if(nDay == i)
		{
			SetTextColor(hDC, GetSysColor(COLOR_BTNTEXT));
		}
		else
		{
			COLORREF clTemp = GetSysColor(COLOR_3DLIGHT);
			clTemp -= 0x00101010;
			SetTextColor(hDC, clTemp);
		}

		TextOut(hDC, nX + 35 * i, nY, s_szDayList[i], 2);
	}

}

void DrawAlarm(HDC hDC, int nX, int nY, BOOL fOn, BOOL fDark)
{
	if(fDark)
	{
		SetTextColor(hDC, GetSysColor(COLOR_BTNTEXT));
	}
	else
	{
		COLORREF clTemp = GetSysColor(COLOR_3DLIGHT);
		clTemp -= 0x00101010;
		SetTextColor(hDC, clTemp);
	}

	if(fOn)
	{
		COLORREF nCol = SetTextColor(hDC, GetSysColor(COLOR_3DLIGHT));
		TextOut(hDC, nX, nY, s_szAlarm0, _tcslen(s_szAlarm0));
		SetTextColor(hDC, nCol);
		TextOut(hDC, nX, nY, s_szAlarm1, _tcslen(s_szAlarm1));
	}
	else
	{
		COLORREF nCol = SetTextColor(hDC, GetSysColor(COLOR_3DLIGHT));
		TextOut(hDC, nX, nY, s_szAlarm1, _tcslen(s_szAlarm1));
		SetTextColor(hDC, nCol);
		TextOut(hDC, nX, nY, s_szAlarm0, _tcslen(s_szAlarm0));
	}
}

static BOOL s_fHide = TRUE;

void UpdateWatch(HDC hDC, SYSTEMTIME& SysTime)
{
	int nX = CX_SEGMENT + 15;
	
	int n1 = -1, n2 = -1, n3 = -1, n4 = -1, n5 = -1, n6 = -1;

	if(!g_AppOption.uAlarm && (g_AppOption.uDate || (g_AppOption.uSet > 3)))
	{
		n1 = (SysTime.wDay) / 10;
		n2 = (SysTime.wDay) % 10;
		
		n3 = (SysTime.wMonth) / 10;
		n4 = (SysTime.wMonth) % 10;

		n5 = ((SysTime.wYear) % 100) / 10;
		n6 = ((SysTime.wYear) % 100) % 10;

		if(g_AppOption.uDate) g_AppOption.uDate--;
	}
	else
	{
		n1 = (SysTime.wHour) / 10;
		n2 = (SysTime.wHour) % 10;
		
		n3 = (SysTime.wMinute) / 10;
		n4 = (SysTime.wMinute) % 10;

		n5 = (SysTime.wSecond) / 10;
		n6 = (SysTime.wSecond) % 10;
	}

	if((g_AppOption.uSet) && (s_fHide ^= TRUE) && g_AppOption.uCount)
	{
		switch(g_AppOption.uSet)
		{
			case 1:
			case 4:
			{
				if(g_AppOption.uAlarm & (g_AppOption.uSet == 4))
				{
					break;
				}
				n6 = -1;
				n5 = -1;
				break;
			}
			
			case 2:
			case 5:
			{
				n4 = -1;
				n3 = -1;
				break;
			}

			case 3:
			case 6:
			{
				n2 = -1;
				n1 = -1;
				break;
			}
		}

		if(g_AppOption.uCount) 
		{
			g_AppOption.uCount--;
			if(!g_AppOption.uCount)
			{
				g_AppOption.uSet = 7;
				OnSet(g_AppData.hMainWnd);
			}
		}
	}
	
	DrawSegment(hDC, 15, 28, n1);
	DrawSegment(hDC, 15 + nX, 28, n2);

	nX *= 2;
	DrawSeparator(hDC, 15 + nX, 28, TRUE);


	nX += 15;
	DrawSegment(hDC, 15 + nX, 28, n3);
	DrawSegment(hDC, 15 + CX_SEGMENT + 15 + nX, 28, n4);

	nX *= 2;
	DrawSeparator(hDC, 15 + nX - 15, 28, TRUE);

	DrawSegment(hDC, 15 + nX, 28, n5);
	DrawSegment(hDC, 15 + CX_SEGMENT + 15 + nX, 28, n6);

	DrawWeekDays(hDC, 15, 4, (SysTime.wDayOfWeek));

	DrawAlarm(hDC, 260, 4, g_AppOption.AlarmTime.fActive, (g_AppOption.uAlarm & (g_AppOption.uSet == 4)) ? s_fHide : TRUE);
}

void ReDraw(HDC hDC)
{
	_ASSERTE((s_hLightBrush == NULL) && (s_hDarkBrush == NULL));

	HPEN hOldPen = (HPEN)SelectObject(hDC, GetStockObject(NULL_PEN));

	COLORREF clTemp = GetSysColor(COLOR_3DLIGHT);
	clTemp -= 0x00101010;
	LOGBRUSH lb = {BS_SOLID,clTemp,0};
	s_hLightBrush = CreateBrushIndirect(&lb);
	lb.lbColor = GetSysColor(COLOR_BTNTEXT);
	s_hDarkBrush = CreateBrushIndirect(&lb);

	HFONT hFont = (HFONT)SendMessage(g_AppData.hMainWnd, WM_GETFONT, 0, 0);
	SetBkColor(hDC, GetSysColor(COLOR_3DFACE));
	HFONT hOldFont = (HFONT)SelectObject(hDC, hFont);
	
	if(g_AppData.fSet || g_AppOption.uTimer == 1 || g_AppOption.uTimer == 3 || g_AppOption.uAlarm)
	{
		UpdateWatch(hDC, g_AppData.OffsetTime);
		if(g_AppOption.uAlarm && !g_AppOption.uSet) 
			g_AppOption.uAlarm--;
		g_AppData.fSet = FALSE;
	}
	else if(g_AppOption.uTimer == 2)
	{
		if(g_AppData.OffsetTime.wSecond == 9)
		{
			g_AppData.OffsetTime.wSecond = 0;
			g_AppData.OffsetTime.wMinute++;
			if(g_AppData.OffsetTime.wMinute == 59)
			{
				g_AppData.OffsetTime.wMinute = 0;
				g_AppData.OffsetTime.wHour++;
				if(g_AppData.OffsetTime.wHour == 99)
				{
					g_AppData.OffsetTime.wHour = 0;
				}
			}
		}
		else
		{
			g_AppData.OffsetTime.wSecond++;
		}
		UpdateWatch(hDC, g_AppData.OffsetTime);
	}
	else
	{
		SYSTEMTIME st;
		GetLocalTime(&st);
		UpdateWatch(hDC, st);
	}

	SelectObject(hDC, hOldPen);
	SelectObject(hDC, hOldFont);
	DeleteObject(s_hLightBrush);
	DeleteObject(s_hDarkBrush);

#ifdef _DEBUG
	s_hLightBrush = NULL;
	s_hDarkBrush = NULL;
#endif

}

static void OnPaint(HWND hWnd)
{
	if(!IsIconic(g_AppData.hMainWnd) && g_AppData.fShow)
	{
		PAINTSTRUCT ps;
		HDC hDC = BeginPaint(hWnd, &ps);
		ReDraw(hDC);
		EndPaint(hWnd, &ps);
	}
}


static HWND s_hWnd = NULL;

LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	if(hWnd == s_hWnd)
	{
		switch(uMsg)
		{
			HANDLE_MSG(hWnd, WM_PAINT, OnPaint);
		}
	}
	return CallWindowProc(oldWndPros, hWnd, uMsg, wParam, lParam);
}

BOOL InitWatch(HWND hWnd)
{
	if(oldWndPros || !hWnd)
		return FALSE;

	LoadString(g_AppData.hInstance, IDS_ALARM0, s_szAlarm0, 10);
	LoadString(g_AppData.hInstance, IDS_ALARM1, s_szAlarm1, 10);

	for(int i = 0; i < 7; i++)
		LoadString(g_AppData.hInstance, s_dwIDS[i], s_szDayList[i], 3);

	s_hWnd = hWnd;
	oldWndPros = (WNDPROC)SetWindowLong(hWnd, GWL_WNDPROC, (LONG)WndProc);
	return TRUE;
}

BOOL FreeWatch(HWND hWnd)
{
	if(!oldWndPros || !hWnd)
		return FALSE;

	SetWindowLong(hWnd, GWL_WNDPROC, (LONG)oldWndPros );
	return TRUE;
}

BOOL OnMultimediaAlarm()
{
	if(!(IsMultimedia() & AC_WAVE))
	{
		if(!g_AppOption.AlarmSet.fMultimedia)
		{
			ReportBox(IDS_NO_DEVICE, MB_OK | MB_ICONSTOP);
			return FALSE;
		}
		g_AppData.fStopSound = FALSE;
		for(int i = 0; i < 60; i++)
		{
			MessageBeep(0xFFFFFFFF);
			DWORD dwStart = GetTickCount();
			dwStart += 500;
			while(dwStart > GetTickCount());
			if(g_AppData.fStopSound)
				break;
		}
		g_AppData.fStopSound = FALSE;
		return TRUE;
	}
	
	if(g_AppOption.AlarmSet.szFileName1[0] && !g_AppOption.AlarmSet.fMultimedia)
	{
		if(!sndPlaySound(g_AppOption.AlarmSet.szFileName1, SND_ASYNC))
		{
			ReportBox(IDS_PS_FAILED, MB_OK | MB_ICONSTOP);
			return FALSE;
		}
		return TRUE;
	}

	HANDLE hWave = FindResource(g_AppData.hInstance, MAKEINTRESOURCE(IDR_WAVE1), s_szWave);
	if(hWave)
	{
		HANDLE hRes = LoadResource(g_AppData.hInstance, (HRSRC)hWave);	
		if(hRes)
		{
			LPCSTR lpRes = (LPCSTR)LockResource(hRes);
			if(lpRes)
			{
				g_AppData.fStopSound = FALSE;
				for(int i = 0; i < 60; i++)
				{
					if(!sndPlaySound(lpRes, SND_SYNC | SND_MEMORY))
					{
						ReportBox(IDS_PS_FAILED, MB_OK | MB_ICONSTOP);
						break;
					}
					DWORD dwStart = GetTickCount();
					dwStart += 500;
					while(dwStart > GetTickCount());
					if(g_AppData.fStopSound)
						break;
				}
				g_AppData.fStopSound = FALSE;
				UnlockResource(lpRes);
			}
			FreeResource(hRes);
		}
		return TRUE;
	}
	return FALSE;
}

BOOL OnExecuteAlarm()
{
	STARTUPINFO si;
	PROCESS_INFORMATION pi;

	memset(&si, 0, sizeof(STARTUPINFO));
	si.cb = sizeof(STARTUPINFO);

	if(!CreateProcess(NULL, g_AppOption.AlarmSet.szFileName2, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
	{
		TCHAR szErrorText[512];
		TCHAR szTemp[256];
		LoadString(g_AppData.hInstance, IDS_ERROR_EXEC, szTemp, 255);
		sprintf(szErrorText, szTemp, g_AppOption.AlarmSet.szFileName2);
		ReportBox(szErrorText, MB_OK | MB_ICONSTOP);
		return FALSE;
	}
	CloseHandle(pi.hProcess);
	return TRUE;
}

BOOL OnMessageAlarm()
{
	if(g_AppOption.AlarmSet.szMesText[0] && !g_AppOption.AlarmSet.fMessage)
		ReportBox(g_AppOption.AlarmSet.szMesText, MB_ICONINFORMATION | MB_OK);
	else
		ReportBox(IDS_ALARM_ACTIE, MB_ICONINFORMATION | MB_OK);
	return TRUE;
}

BOOL OnCloseAlarm()
{
/*	if(g_AppOption.AlarmSet.fConfirm)
	{
		if(ReportBox(IDS_CLOSE_WIN, MB_ICONINFORMATION | MB_YESNO | MB_SYSTEMMODAL) == IDNO)
			return FALSE;
	}*/
	BOOL bRet = FALSE;
	OSVERSIONINFO osvi;
	memset(&osvi, 0, sizeof(OSVERSIONINFO));
	osvi.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
	if (!GetVersionEx(&osvi))
	{
		ShowOSError(IDS_SYS_ERROR, GetLastError());
		return FALSE;
	}
	if (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT)
	{
		HANDLE hToken;
		LUID luid;
		TOKEN_PRIVILEGES tp;
		if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
		{
			ShowOSError(IDS_SYS_ERROR, GetLastError());
			return FALSE;
		}
		if (!LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &luid))
		{
			ShowOSError(IDS_SYS_ERROR, GetLastError());
			return FALSE;
		}
		tp.PrivilegeCount           = 1;
		tp.Privileges[0].Luid       = luid;
		tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
		if (!AdjustTokenPrivileges(hToken, FALSE, &tp, sizeof(TOKEN_PRIVILEGES), NULL, NULL))
		{
			ShowOSError(IDS_SYS_ERROR, GetLastError());
			return FALSE;
		}
		bRet = ExitWindowsEx(g_AppOption.AlarmSet.fConfirm ? EWX_SHUTDOWN : EWX_SHUTDOWN | EWX_FORCE, 0);
		if (!AdjustTokenPrivileges(hToken, TRUE, &tp, sizeof(TOKEN_PRIVILEGES), NULL, NULL))
		{
			ShowOSError(IDS_SYS_ERROR, GetLastError());
			return FALSE;
		}
	}
	else
	{
		bRet = ExitWindowsEx(g_AppOption.AlarmSet.fConfirm ? EWX_SHUTDOWN : EWX_SHUTDOWN | EWX_FORCE, 0);
	}
	return bRet;
}

BOOL WINAPI TreadAlarm(LPVOID)
{
	switch(g_AppOption.AlarmSet.uAlarmNot)
	{
		case 0:
		{
			return OnMultimediaAlarm();
		}

		case 1:
		{
			return OnExecuteAlarm();
		}

		case 3:
		{
			return OnCloseAlarm();
		}

		default:
		{
			return OnMessageAlarm();
		}
	}
}

BOOL OnAlarmCheck()
{
	SYSTEMTIME LocalTime;
	GetLocalTime(&LocalTime);
	if(g_AppOption.AlarmTime.fActive && 
		(LocalTime.wHour == (WORD)g_AppOption.AlarmTime.dwHour) &&
		(LocalTime.wMinute == (WORD)g_AppOption.AlarmTime.dwMinute) &&
		(LocalTime.wSecond == (WORD)g_AppOption.AlarmTime.dwSecond))
	{
		DWORD dwID;
		HANDLE hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)TreadAlarm, 0, 0, &dwID);
		if(hThread)
		{
			CloseHandle(hThread);
			return TRUE;
		}
		else
		{
			return FALSE;
		}
	}
	else
	{
		switch(g_AppOption.AlarmSet.uClockNot)
		{
			case 2:
			{
				if(!g_AppOption.uTimer && !g_AppOption.uSet && !LocalTime.wMinute && !LocalTime.wSecond)
					TimeSound(LocalTime.wHour == 0 ? 24 : LocalTime.wHour);
				break;
			}
			case 1:
			case 3:
			{
				if(!g_AppOption.uTimer && !g_AppOption.uSet && LocalTime.wMinute == 30 && !LocalTime.wSecond)
					TimeSound(1);
				else if(!g_AppOption.uTimer && !g_AppOption.uSet && !LocalTime.wMinute && !LocalTime.wSecond)
					TimeSound(LocalTime.wHour == 0 ? 24 : LocalTime.wHour);
				break;
			}

		}
		return TRUE;
	}
	return FALSE;
}

VOID CALLBACK TimerProc(HWND hWnd, UINT uMsg, UINT idEvent, DWORD dwTime)
{
	if(!IsIconic(g_AppData.hMainWnd) && g_AppData.fShow)
	{
		HDC hDC = GetDC(g_AppData.hWatchWnd);
		ReDraw(hDC);
		ReleaseDC(g_AppData.hWatchWnd, hDC);
	}

	if(/*g_AppOption.AlarmTime.fActive && */!(g_AppOption.uSet && g_AppOption.uAlarm))
		OnAlarmCheck();
}

void GetAlarmTime(SYSTEMTIME& AlarmTime)
{
	AlarmTime.wHour = (WORD)g_AppOption.AlarmTime.dwHour;
	AlarmTime.wMinute = (WORD)g_AppOption.AlarmTime.dwMinute;
	AlarmTime.wSecond = (WORD)g_AppOption.AlarmTime.dwSecond;
	AlarmTime.wDayOfWeek = 0xffff;
}

void SetAlarmTime(SYSTEMTIME& AlarmTime)
{
	g_AppOption.AlarmTime.dwHour = AlarmTime.wHour;
	g_AppOption.AlarmTime.dwMinute = AlarmTime.wMinute;
	g_AppOption.AlarmTime.dwSecond = AlarmTime.wSecond;
}

/*
int ReportBox(LPCTSTR lpszMessage, int nMode)
{
	MSGBOXPARAMS MsgBox;

	MsgBox.cbSize = sizeof(MSGBOXPARAMS);
	MsgBox.hwndOwner = g_AppData.hMainWnd;
	MsgBox.hInstance = 0;
	MsgBox.lpszText = lpszMessage;
	MsgBox.lpszCaption = g_AppData.szAppName;
	MsgBox.dwStyle = nMode | MB_USERICON;
	
	if(nMode & MB_ICONSTOP)
		MsgBox.lpszIcon = MAKEINTRESOURCE(IDI_ERROR);
	else if(nMode & MB_ICONINFORMATION)
		MsgBox.lpszIcon = MAKEINTRESOURCE(IDI_INFO);
	else
		MsgBox.lpszIcon = MAKEINTRESOURCE(IDI_ALARM);
	MsgBox.dwContextHelpId = 0;
	MsgBox.lpfnMsgBoxCallback = NULL;
	MsgBox.dwLanguageId = MAKELANGID(LANG_NEUTRAL, SUBLANG_SYS_DEFAULT);
	
	MessageBoxIndirect(&MsgBox);
	return GetLastError();
}
*/
///////////////////////////////////////////////////////////////////////////////

#ifdef _DEBUG
void AlarmTrace(LPCTSTR lpszFormat, ...)
{
	va_list args;
	va_start(args, lpszFormat);

	TCHAR szBuffer[512];

	_vstprintf(szBuffer, lpszFormat, args);

	OutputDebugString(szBuffer);

	va_end(args);
}
#endif //_DEBUG
