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

#include <crtdbg.h>
#ifdef _DEBUG
#define	TRACE	AlarmTrace
void AlarmTrace(LPCTSTR lpszFormat, ...);
#else
#define	TRACE	((void)0)
#endif //_DEBUG

#define HANDLE_WINMSG(hWnd, message, fn) \
	case (message): return (hWnd, uMsg, HANDLE_##message((hWnd), (wParam), (lParam), (fn)))

// The normal HANDLE_MSG macro in WINDOWSX.H does not work properly for dialog
// boxes because DlgProc's return a BOOL instead of an LRESULT (like
// WndProcs). This adgHANDLE_DLGMSG macro corrects the problem:
#define adgHANDLE_DLGMSG(hWnd, message, fn)                          \
   case (message): return (SetDlgMsgResult(hWnd, uMsg,               \
      HANDLE_##message((hWnd), (wParam), (lParam), (fn))))

#define	AC_WAVE		1
#define	AC_MIDI		2

struct ALARMTIME
{
	BOOL		fActive;
	DWORD		dwSecond;
	DWORD		dwMinute;
	DWORD		dwHour;
};

struct APPDATA
{
	TCHAR		szAppName[256];
	HINSTANCE	hInstance;
	HWND		hWatchWnd;
	HWND		hMainWnd;
	BOOL		fShow;
	SYSTEMTIME	OffsetTime;
	BOOL		fSet;
	BOOL		fStopSound;
};

struct APPSETTINGS
{
	UINT		uAlarmNot;
	TCHAR		szFileName1[MAX_PATH];
	TCHAR		szFileName2[MAX_PATH];
	TCHAR		szMesText[256];
	BOOL		fConfirm;
	BOOL		fMultimedia;
	BOOL		fMessage;
	UINT		uClockNot;
	TCHAR		szFileName3[MAX_PATH];
	UINT		uLastPage;
};

struct APPOPTION
{
	UINT		uAlarm;
	UINT		uDate;
	UINT		uSet;
	UINT		uCount;
	UINT		uTimer;
	ALARMTIME	AlarmTime;
	APPSETTINGS	AlarmSet;
};

typedef struct tagSCHDATA
{
	long nCommand;
	long nFrecq;
	BOOL bEnable;
	DWORD dwHotKey;
	TCHAR szPath[MAX_PATH + 1];
	TCHAR szDesc[MAX_PATH + 1];
	SYSTEMTIME st00;
	SYSTEMTIME st01;
	long nMinutes10;
	SYSTEMTIME st20;
	long nDayOfWeek30;
	SYSTEMTIME st31;
	long nDayOfMonth40;
	SYSTEMTIME st41;
	SYSTEMTIME st50;
	SYSTEMTIME st51;
} SCHDATA, *LPSCHDATA;

extern APPDATA g_AppData;
extern APPOPTION g_AppOption;

inline int ReportBox(LPCTSTR lpszMessage, int nMode = MB_OK)
{
	return MessageBox(g_AppData.hMainWnd, lpszMessage, g_AppData.szAppName, nMode);
}

inline int ReportBox(UINT uMesID, int nMode = MB_OK)
{
	TCHAR szText[256];
	LoadString(g_AppData.hInstance, uMesID, szText, 255);
	return ReportBox(szText, nMode);
}

int ShowOSError(UINT uMesID, DWORD dwError, int nMode = MB_OK|MB_ICONERROR);

BOOL InitWatch(HWND hWnd);
BOOL FreeWatch(HWND hWnd);
VOID CALLBACK TimerProc(HWND hWnd, UINT uMsg, UINT idEvent, DWORD dwTime);
void GetAlarmTime(SYSTEMTIME& AlarmTime);
void SetAlarmTime(SYSTEMTIME& AlarmTime);

void OnSet(HWND hWnd);
void ShowSettingsDlg(HINSTANCE hInstance, HWND hWnd);
DWORD IsMultimedia();

BOOL InitToolBar(HWND hWnd);
BOOL FreeToolBar(HWND hWnd);

DWORD GetRegDWORD(LPCTSTR lpszFolder, LPCTSTR lpszKey, DWORD dwDefault = 0);
BOOL GetRegString(LPCTSTR lpszFolder, LPCTSTR lpszKey, LPCTSTR lpszDefault, LPTSTR lpszReturnedString, DWORD dwSize);
BOOL SetRegDWORD(LPCTSTR lpszFolder, LPCTSTR lpszKey, DWORD dwData);
BOOL SetRegString(LPCTSTR lpszFolder, LPCTSTR lpszKey, LPCTSTR lpszString);

BOOL OpenDBSettings();
BOOL CloseDBSettings();
BOOL ReadDBSettings(long nIndex, LPSCHDATA lpSetData);
BOOL WriteDBSettings(long nIndex, LPSCHDATA lpSetData);
BOOL ClearDBSettings();
BOOL HotKeyMonitor(WPARAM wParam, LPARAM lParam);
long& GetDBRecCount();
BOOL InitTDEdit(HINSTANCE hInst);
