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

#define STRICT
#include <Windows.h>
#include <Windowsx.h>
#include <commctrl.h>
#include <tchar.h>
#include <stdio.h>
#include "Resource.h"
#include "Alarm.h"
#include "tdedit.h"

#define	COL1X	185
#define	COL2X	70
#define	COL3X	150
#define	COL4X	101

static DWORD s_dwIDS[6] = {IDS_FR1, IDS_FR2, IDS_FR3, IDS_FR4, IDS_FR5, IDS_FR6};
#define	S_DWIDS_LEN		sizeof(s_dwIDS) / sizeof(DWORD)

static DWORD s_dwIDS2[6] = {IDS_FRDATE, IDS_FRMINUTES, IDS_FRTIME, IDS_FRWEEKLY, IDS_FRMONTHLY, IDS_FRPERIOD};
#define	S_DWIDS2_LEN		sizeof(s_dwIDS2) / sizeof(DWORD)

static DWORD s_dwIDS3[7] = {IDS_SUNDAY, IDS_MONDAY, IDS_TUESDAY, IDS_WEDNESDAY, IDS_THURSDAY, IDS_FRIDAY, IDS_SATURDAY};

static SCHDATA s_SchData;
static LPSCHDATA s_lpSchData = NULL;

BOOL StartMonitor();

void GetHotKey(LPSCHDATA lpSetData, LPTSTR lpszTemp);
void GetFrecq(LPSCHDATA lpSetData, LPTSTR lpszTemp);
void SetValue(HWND hWnd, LPSCHDATA lpSetData);
void Shedul_OnCommand(HWND hWnd, int id, HWND hWndCtl, UINT codeNotify);
BOOL OnSelectFile(HWND hWnd, UINT uMode = IDC_BUTTON2);

inline void GetWindowPos(HWND hParentWnd, HWND hChildWnd, LPRECT lpRect)
{
	GetWindowRect(hChildWnd, lpRect);
	ScreenToClient(hParentWnd, (LPPOINT)lpRect);
	ScreenToClient(hParentWnd, ((LPPOINT)lpRect)+1);
}

void DelHotKey(LPSCHDATA lpSetData)
{
	if(lpSetData->dwHotKey)
		UnregisterHotKey(g_AppData.hMainWnd, lpSetData->dwHotKey);
}

void SetHotKey(LPSCHDATA lpSetData)
{
	if(lpSetData->dwHotKey)
	{
		BYTE bVKey = (BYTE)(lpSetData->dwHotKey >> 8);
		DWORD dwFlags = 0;
		if(HOTKEYF_CONTROL & bVKey)
			dwFlags |= MOD_CONTROL;
		if(HOTKEYF_SHIFT & bVKey)
			dwFlags |= MOD_SHIFT;
		if(HOTKEYF_ALT & bVKey)
			dwFlags |= MOD_ALT;
		RegisterHotKey(g_AppData.hMainWnd, lpSetData->dwHotKey, dwFlags, (BYTE)lpSetData->dwHotKey);
	}
}

int GetCurrentIndex(HWND hWnd)
{
	HWND ListhWnd = GetDlgItem(hWnd, IDC_EVENTS_LIST);
	if(!ListhWnd)
		return -1;

	return ListView_GetNextItem(ListhWnd, -1, LVNI_SELECTED|LVNI_FOCUSED);
}

void SaveList(HWND hWnd)
{
	HWND ListhWnd = GetDlgItem(hWnd, IDC_EVENTS_LIST);
	if(!ListhWnd)
		return;

	ClearDBSettings();
	long nCount = ListView_GetItemCount(ListhWnd);
	for(int i = 0; i < nCount; i++)
	{
		LV_ITEM lvItem;
		memset(&lvItem, 0, sizeof(LV_ITEM));
		lvItem.mask = LVIF_PARAM|LVIF_STATE;
		lvItem.stateMask = LVIS_STATEIMAGEMASK;
		lvItem.iItem = i;
		if(ListView_GetItem(ListhWnd, &lvItem))
		{
			((LPSCHDATA)lvItem.lParam)->bEnable = (((lvItem.state & LVIS_STATEIMAGEMASK) >> 12) - 1);
			WriteDBSettings(i, (LPSCHDATA)lvItem.lParam);
		}
	}
	StartMonitor();
}

void DeleteItem(HWND hWnd)
{
	HWND ListhWnd = GetDlgItem(hWnd, IDC_EVENTS_LIST);
	if(!ListhWnd)
		return;

	int nIndex;
	if((nIndex = ListView_GetNextItem(ListhWnd, -1, LVNI_SELECTED)) != -1)
	{
		LV_ITEM lvItem;
		memset(&lvItem, 0, sizeof(LV_ITEM));
		lvItem.mask = LVIF_PARAM;
		lvItem.iItem = nIndex;
		if(ListView_GetItem(ListhWnd, &lvItem))
		{
			delete (LPSCHDATA)lvItem.lParam;
		}
		ListView_DeleteItem(ListhWnd, nIndex);
	}
}

void UpdateItem(HWND hWnd, LPSCHDATA lpSetData)
{
	HWND ListhWnd = GetDlgItem(hWnd, IDC_EVENTS_LIST);
	if(!ListhWnd)
		return;

	int nIndex;
	if((nIndex = ListView_GetNextItem(ListhWnd, -1, LVNI_SELECTED)) != -1)
	{
		LV_ITEM lvItem;
		memset(&lvItem, 0, sizeof(LV_ITEM));
		lvItem.mask = LVIF_PARAM;
		lvItem.iItem = nIndex;
		if(ListView_GetItem(ListhWnd, &lvItem))
			delete (LPSCHDATA)lvItem.lParam;
		lvItem.lParam = (LONG)lpSetData;
		lvItem.mask = LVIF_PARAM|LVIF_TEXT;
		lvItem.pszText = lpSetData->szDesc;
		lvItem.cchTextMax = _tcslen(lpSetData->szDesc);
		ListView_SetItem(ListhWnd, &lvItem);
		TCHAR szTemp[255];
		LoadString(g_AppData.hInstance, s_dwIDS[lpSetData->nFrecq], szTemp, 255);
		lvItem.mask = LVIF_TEXT;
		lvItem.pszText = szTemp;
		lvItem.cchTextMax = _tcslen(szTemp);
		lvItem.iSubItem = 1;
		ListView_SetItem(ListhWnd, &lvItem);
		GetFrecq(lpSetData, szTemp);
		lvItem.pszText = szTemp;
		lvItem.cchTextMax = _tcslen(szTemp);
		lvItem.iSubItem = 2;
		ListView_SetItem(ListhWnd, &lvItem);
		GetHotKey(lpSetData, szTemp);
		lvItem.pszText = szTemp;
		lvItem.cchTextMax = _tcslen(szTemp);
		lvItem.iSubItem = 3;
		ListView_SetItem(ListhWnd, &lvItem);
		ListView_SetItemState(ListhWnd, nIndex, UINT((int(lpSetData->bEnable) + 1) << 12), LVIS_STATEIMAGEMASK);
	}
}

BOOL GetSelListData(HWND hWnd, LPSCHDATA lpSchData)
{
	HWND ListhWnd = GetDlgItem(hWnd, IDC_EVENTS_LIST);
	if(!ListhWnd)
		return FALSE;

	int nIndex;
	if((nIndex = ListView_GetNextItem(ListhWnd, -1, LVNI_SELECTED)) != -1)
	{
		LV_ITEM lvItem;
		memset(&lvItem, 0, sizeof(LV_ITEM));
		lvItem.mask = LVIF_PARAM|LVIF_STATE;
		lvItem.stateMask = LVIS_STATEIMAGEMASK;
		lvItem.iItem = nIndex;
		if(ListView_GetItem(ListhWnd, &lvItem))
		{
			memcpy(lpSchData, (LPSCHDATA)lvItem.lParam, sizeof(SCHDATA));
			lpSchData->bEnable = (((lvItem.state & LVIS_STATEIMAGEMASK)>>12)-1);
		}
	}
	return FALSE;
}

void GetHotKey(LPSCHDATA lpSetData, LPTSTR lpszTemp)
{
	if(lpSetData->dwHotKey == 0)
	{
		LoadString(g_AppData.hInstance, IDS_ABSENCE, lpszTemp, 255);
	}
	else
	{
		BYTE bVKey = (BYTE)lpSetData->dwHotKey;
		TCHAR szKeyName[256];
		long lKey = (MapVirtualKey(bVKey, 0) << 16) | 0x03000000;
		GetKeyNameText(lKey, szKeyName, 255);

		bVKey = (BYTE)(lpSetData->dwHotKey >> 8);
		TCHAR szTemp[256] = _T("");
		if(HOTKEYF_CONTROL & bVKey)
			_tcscat(szTemp, _T("Ctrl+"));
		if(HOTKEYF_SHIFT & bVKey)
			_tcscat(szTemp, _T("Shift+"));
		if(HOTKEYF_ALT & bVKey)
			_tcscat(szTemp, _T("Alt+"));
		_stprintf(lpszTemp, _T("%s%s"), szTemp, szKeyName);
	}
}

void GetFrecq(LPSCHDATA lpSetData, LPTSTR lpszTemp)
{
	TCHAR szTemp[256];
	TCHAR szTemp2[256];
	TCHAR szTemp3[256];
	SYSTEMTIME st;
	GetLocalTime(&st);
	switch(lpSetData->nFrecq)
	{
		case 0:
		{
			LoadString(g_AppData.hInstance, IDS_SCHEDULED1, szTemp, 255);
			lpSetData->st00.wYear += st.wYear - (st.wYear % 100);
			GetDateFormat(LOCALE_USER_DEFAULT, DATE_LONGDATE, &lpSetData->st00, NULL, szTemp2, 255);
			lpSetData->st00.wYear -= st.wYear - (st.wYear % 100);
			GetTimeFormat(LOCALE_USER_DEFAULT, TIME_NOSECONDS|TIME_FORCE24HOURFORMAT, &lpSetData->st01, NULL, szTemp3, 255);
			_stprintf(lpszTemp, szTemp, szTemp2, szTemp3);
			break;
		}
		case 1:
		{
			LoadString(g_AppData.hInstance, IDS_SCHEDULED2, szTemp, 255);
			_stprintf(lpszTemp, szTemp, lpSetData->nMinutes10);
			break;
		}
		case 2:
		{
			LoadString(g_AppData.hInstance, IDS_SCHEDULED3, szTemp, 255);
			GetTimeFormat(LOCALE_USER_DEFAULT, TIME_NOSECONDS|TIME_FORCE24HOURFORMAT, &lpSetData->st20, NULL, szTemp2, 255);
			_stprintf(lpszTemp, szTemp, szTemp2);
			break;
		}
		case 3:
		{
			LoadString(g_AppData.hInstance, IDS_SCHEDULED4, szTemp, 255);
			LoadString(g_AppData.hInstance, s_dwIDS[lpSetData->nFrecq], szTemp2, 255);
			GetTimeFormat(LOCALE_USER_DEFAULT, TIME_NOSECONDS|TIME_FORCE24HOURFORMAT, &lpSetData->st31, NULL, szTemp3, 255);
			_stprintf(lpszTemp, szTemp, szTemp2, szTemp3);
			break;
		}
		case 4:
		{
			LoadString(g_AppData.hInstance, IDS_SCHEDULED5, szTemp, 255);
			GetTimeFormat(LOCALE_USER_DEFAULT, TIME_NOSECONDS|TIME_FORCE24HOURFORMAT, &lpSetData->st41, NULL, szTemp2, 255);
			_stprintf(lpszTemp, szTemp, lpSetData->nDayOfMonth40, szTemp2);
			break;
		}
		case 5:
		{
			LoadString(g_AppData.hInstance, IDS_SCHEDULED6, szTemp, 255);
			GetTimeFormat(LOCALE_USER_DEFAULT, TIME_NOSECONDS|TIME_FORCE24HOURFORMAT, &lpSetData->st50, NULL, szTemp2, 255);
			_stprintf(lpszTemp, szTemp, szTemp2);
			break;
		}
	}
}

void SetLVCheck (WPARAM ItemIndex, BOOL bCheck)
{
}

void InsertItem(HWND hWnd, LPSCHDATA lpSetData, long nIndex)
{
	try
	{
		LV_ITEM lvItem;
		lvItem.mask = LVIF_TEXT|LVIF_PARAM;
		lvItem.iItem = nIndex;
		lvItem.state = 0;
		lvItem.stateMask = 0;
		lvItem.iImage = 0;
		lvItem.lParam = (LONG)lpSetData;

		lvItem.pszText = lpSetData->szDesc;
		lvItem.cchTextMax = _tcslen(lpSetData->szDesc);
		lvItem.iSubItem = 0;
		ListView_InsertItem(hWnd, &lvItem);
		
		TCHAR szTemp[255];
		LoadString(g_AppData.hInstance, s_dwIDS[lpSetData->nFrecq], szTemp, 255);
		lvItem.mask = LVIF_TEXT;
		lvItem.pszText = szTemp;
		lvItem.cchTextMax = _tcslen(szTemp);
		lvItem.iSubItem = 1;
		ListView_SetItem(hWnd, &lvItem);

		GetFrecq(lpSetData, szTemp);
		lvItem.pszText = szTemp;
		lvItem.cchTextMax = _tcslen(szTemp);
		lvItem.iSubItem = 2;
		ListView_SetItem(hWnd, &lvItem);

		GetHotKey(lpSetData, szTemp);
		lvItem.pszText = szTemp;
		lvItem.cchTextMax = _tcslen(szTemp);
		lvItem.iSubItem = 3;
		ListView_SetItem(hWnd, &lvItem);
		ListView_SetItemState(hWnd, nIndex, UINT((int(lpSetData->bEnable) + 1) << 12), LVIS_STATEIMAGEMASK);
	}
	catch(...)
	{
		_ASSERTE(FALSE);
		delete lpSetData;
	}
}

void AddToList(HWND hWnd, LPSCHDATA lpSetData)
{
	HWND ListhWnd = GetDlgItem(hWnd, IDC_EVENTS_LIST);
	if(!ListhWnd)
		return;
	InsertItem(ListhWnd, lpSetData, ListView_GetItemCount(ListhWnd));
}

void FiilList(HWND hWnd)
{
	HWND ListhWnd = GetDlgItem(hWnd, IDC_EVENTS_LIST);
	if(!ListhWnd)
		return;
	LPSCHDATA lpSetData;
	for(long i = 0; ReadDBSettings(i, lpSetData = new SCHDATA); i++)
	{
		InsertItem(ListhWnd, lpSetData, i);
	}
	delete lpSetData;
}

void InitList(HWND hWnd)
{
	HWND ListhWnd = GetDlgItem(hWnd, IDC_EVENTS_LIST);
	if(!ListhWnd)
		return;
	
	SendMessage(ListhWnd, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_FULLROWSELECT|LVS_EX_CHECKBOXES);

	LV_COLUMN TaskList;
	TCHAR szTemp[255];

	TaskList.fmt = LVCFMT_LEFT;
	TaskList.cx = COL1X;
	TaskList.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT ;
	TaskList.cchTextMax = 255;
	TaskList.iSubItem  = -1;
	LoadString(g_AppData.hInstance, IDS_COL1, szTemp, 255);
	TaskList.pszText = szTemp;
	ListView_InsertColumn(ListhWnd, 0, &TaskList);

	TaskList.cx = COL2X;
	LoadString(g_AppData.hInstance, IDS_COL2, szTemp, 255);
	TaskList.pszText = szTemp;
	ListView_InsertColumn(ListhWnd, 1, &TaskList);

	TaskList.cx = COL3X;
	LoadString(g_AppData.hInstance, IDS_COL3, szTemp, 255);
	TaskList.pszText = szTemp;
	ListView_InsertColumn(ListhWnd, 2, &TaskList);

	TaskList.cx = COL4X;
	LoadString(g_AppData.hInstance, IDS_COL4, szTemp, 255);
	TaskList.pszText = szTemp;
	ListView_InsertColumn(ListhWnd, 3, &TaskList);
}

BOOL Shedul_OnInitDialog(HWND hWnd, HWND hWndFocus, LPARAM lParam)
{
	TCHAR szTemp[255];
	SendMessage(hWnd, WM_SETICON, TRUE, (LPARAM)LoadIcon(g_AppData.hInstance, MAKEINTRESOURCE(IDI_CLOCK_SCHEDULER)));    
	SendMessage(hWnd, WM_SETICON, FALSE, (LPARAM)LoadIcon(g_AppData.hInstance, MAKEINTRESOURCE(IDI_CLOCK_SCHEDULER)));    
	_ASSERTE(lParam);
	if(!lParam)
		EndDialog(hWnd, -1);
	s_lpSchData = (LPSCHDATA)lParam;
	memcpy(&s_SchData, s_lpSchData, sizeof(SCHDATA));
	switch(s_SchData.nCommand)
	{
		case IDC_ADD:
			LoadString(g_AppData.hInstance, IDS_ADDEVENT, szTemp, 255);
			SetWindowText(hWnd, szTemp);
		break;
		case IDC_EDIT:
			LoadString(g_AppData.hInstance, IDS_EDITEVENT, szTemp, 255);
			SetWindowText(hWnd, szTemp);
		break;
		case IDC_COPY:
			LoadString(g_AppData.hInstance, IDS_COPYEVENT, szTemp, 255);
			SetWindowText(hWnd, szTemp);
		break;
	}
	SetValue(hWnd, &s_SchData);
	HWND hWndFrList = GetDlgItem(hWnd, IDC_FRLIST);
	if(hWndFrList)
	{
		for(int i = 0; i < S_DWIDS_LEN; i++)
		{
			LoadString(g_AppData.hInstance, s_dwIDS[i], szTemp, 255);
			SendMessage(hWndFrList, CB_ADDSTRING, 0, (LPARAM)szTemp);
		}
		SendMessage(hWndFrList, CB_SETCURSEL, s_SchData.nFrecq, 0);
		Shedul_OnCommand(hWnd, IDC_FRLIST, hWndFrList, CBN_SELCHANGE);
	}
	return TRUE;
}

void SaveRtValue(HWND hWnd, HWND hWndData, HWND hWndTime, long nSel)
{
	TCHAR szTemp[255];
	switch(nSel)
	{
		case 0:
			SendMessage(hWndData, TDM_GETDATA, (WPARAM)&s_SchData.st00, 0);
			SendMessage(hWndTime, TDM_GETDATA, (WPARAM)&s_SchData.st01, 0);
		break;
		case 1:
			if(s_SchData.nMinutes10 > 10)
			{
				SendMessage(hWndData, TDM_GETTEXT, 255, (LPARAM)szTemp);
				s_SchData.nMinutes10 = _ttol(szTemp);
			}
			else
			{
				SendMessage(hWndData, TDM_GETTEXT, 255, (LPARAM)szTemp);
				s_SchData.nMinutes10 = _ttol(szTemp);
			}
			SendMessage(hWndData, TDM_GETRANGE, 0, 0);
		break;
		case 2:
			SendMessage(hWndData, TDM_GETDATA, (WPARAM)&s_SchData.st20, 0);
		break;
		case 3:
			s_SchData.nDayOfWeek30 = (short)SendMessage(hWndData, TDM_GETPOS, 0, 0);
			SendMessage(hWndTime, TDM_GETDATA, (WPARAM)&s_SchData.st31, 0);
		break;
		case 4:
			SendMessage(hWndData, TDM_GETTEXT, 255, (LPARAM)szTemp);
			s_SchData.nDayOfMonth40 = _ttol(szTemp);
			SendMessage(hWndTime, TDM_GETDATA, (WPARAM)&s_SchData.st41, 0);
		break;
		case 5:
			SendMessage(hWndData, TDM_GETDATA, (WPARAM)&s_SchData.st50, 0);
		break;
	}
}

void SetRtValue(HWND hWnd, HWND hWndData, HWND hWndTime, long nSel)
{
	TCHAR szTemp[255];
	switch(nSel)
	{
		case 0:
			SendMessage(hWndData, TDM_CHANGESTYLE, TDS_DATE, 0);
			SendMessage(hWndData, TDM_SETDATA, (WPARAM)&s_SchData.st00, 0);
			SendMessage(hWndTime, TDM_SETDATA, (WPARAM)&s_SchData.st01, 0);
			break;
		case 1:
			SendMessage(hWndData, TDM_CHANGESTYLE, TDS_NUMVALUE, 0);
			if(s_SchData.nMinutes10 >= 10)
			{
				SendMessage(hWndData, TDM_SETTEXT, 0, (LPARAM)_itot(s_SchData.nMinutes10, szTemp, 10));
			}
			else
			{
				szTemp[0] = _T('0');
				SendMessage(hWndData, TDM_SETTEXT, 0, (LPARAM)(_itot(s_SchData.nMinutes10, &szTemp[1], 10) - 1));
			}
			SendMessage(hWndData, TDM_SETRANGE, 0, MAKELONG(59, 0));
			SendMessage(hWndData, TDM_SETPOS, 0, MAKELONG((short)s_SchData.nMinutes10, 0));
		break;
		case 2:
			SendMessage(hWndData, TDM_CHANGESTYLE, TDS_TIME, 0);
			SendMessage(hWndData, TDM_SETDATA, (WPARAM)&s_SchData.st20, 0);
		break;
		case 3:
			SendMessage(hWndData, TDM_CHANGESTYLE, TDS_STRVALUE|TDS_READONLY, 0);
			LoadString(g_AppData.hInstance, s_dwIDS3[s_SchData.nDayOfWeek30], szTemp, 255);
			SendMessage(hWndData, TDM_SETTEXT, 0, (LPARAM)szTemp);
			SendMessage(hWndData, TDM_SETRANGE, 0, MAKELONG(6, 0));
			SendMessage(hWndData, TDM_SETPOS, 0, MAKELONG((short)s_SchData.nDayOfWeek30, 0));
			SendMessage(hWndTime, TDM_SETDATA, (WPARAM)&s_SchData.st31, 0);
		break;
		case 4:
			SendMessage(hWndData, TDM_CHANGESTYLE, TDS_NUMVALUE, 0);
			SendMessage(hWndData, TDM_SETTEXT, 0, (LPARAM)_itot(s_SchData.nDayOfMonth40, szTemp, 10));
			SendMessage(hWndData, TDM_SETRANGE, 0, MAKELONG(31, 1));
			SendMessage(hWndData, TDM_SETPOS, 0, MAKELONG((short)s_SchData.nDayOfMonth40, 0));
			SendMessage(hWndTime, TDM_SETDATA, (WPARAM)&s_SchData.st41, 0);
		break;
		case 5:
			SendMessage(hWndData, TDM_CHANGESTYLE, TDS_TIME, 0);
			SendMessage(hWndData, TDM_SETDATA, (WPARAM)&s_SchData.st50, 0);
		break;
	}
}

void Shedul_OnCommand(HWND hWnd, int id, HWND hWndCtl, UINT codeNotify)
{
	switch(id)
	{
		case IDC_BUTTON2:
			OnSelectFile(hWnd);
		return;
		case IDOK:
			SaveRtValue(hWnd, GetDlgItem(hWnd, IDC_FRDATA), GetDlgItem(hWnd, IDC_FRTIME), s_SchData.nFrecq);
			GetDlgItemText(hWnd, IDC_EDIT4, s_SchData.szDesc, 255);
			GetDlgItemText(hWnd, IDC_EDIT2, s_SchData.szPath, MAX_PATH);
			s_SchData.dwHotKey = SendMessage(GetDlgItem(hWnd, IDC_HOTKEY1), HKM_GETHOTKEY, 0, 0);
			s_SchData.bEnable = !SendMessage(GetDlgItem(hWnd, IDC_CHECK1), BM_GETCHECK, 0, 0);
			memcpy(&s_SchData.st51, &s_SchData.st50, sizeof(SYSTEMTIME));
			memcpy(s_lpSchData, &s_SchData, sizeof(SCHDATA));
		case IDCANCEL:
			EndDialog(hWnd, id);
		break;

		case IDC_FRLIST:
		{
			if(codeNotify == CBN_SELCHANGE)
			{
				if(s_SchData.nFrecq != -1)
					SaveRtValue(hWnd, GetDlgItem(hWnd, IDC_FRDATA), GetDlgItem(hWnd, IDC_FRTIME), s_SchData.nFrecq);
				TCHAR szTemp[255];
				s_SchData.nFrecq = SendMessage(hWndCtl, CB_GETCURSEL, 0, 0);
				LoadString(g_AppData.hInstance, s_dwIDS2[s_SchData.nFrecq], szTemp, 255);
				SetWindowText(GetDlgItem(hWnd, IDC_FRNAME), szTemp);
				ShowWindow(GetDlgItem(hWnd, IDC_FRTIME), (s_SchData.nFrecq == 0 || s_SchData.nFrecq == 3 || s_SchData.nFrecq == 4));
				ShowWindow(GetDlgItem(hWnd, IDC_FR2NAME), (s_SchData.nFrecq == 0 || s_SchData.nFrecq == 3 || s_SchData.nFrecq == 4));

				SetRtValue(hWnd, GetDlgItem(hWnd, IDC_FRDATA), GetDlgItem(hWnd, IDC_FRTIME), s_SchData.nFrecq);
			}
		}
		break;
	}
}

BOOL WINAPI Shedul_WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	switch (uMsg)
	{
		case WM_VSCROLL:
		{
			TCHAR szTemp[255];
			int nPos = (short int) HIWORD(wParam);
			long nSel = SendMessage(GetDlgItem(hWnd, IDC_FRLIST), CB_GETCURSEL, 0, 0);
			if(nSel == 1)
			{
				if(nPos >= 10)
				{
					SendMessage(GetDlgItem(hWnd, IDC_FRDATA), TDM_SETTEXT, 0, (LPARAM)_itot(nPos, szTemp, 10));
				}
				else
				{
					szTemp[0] = _T('0');
					SendMessage(GetDlgItem(hWnd, IDC_FRDATA), TDM_SETTEXT, 0, (LPARAM)(_itot(nPos, &szTemp[1], 10) - 1));
				}
			}
			else if(nSel != 3)
			{
				SendMessage(GetDlgItem(hWnd, IDC_FRDATA), TDM_SETTEXT, 0, (LPARAM)_itot(nPos, szTemp, 10));
			}
			else
			{
				LoadString(g_AppData.hInstance, s_dwIDS3[nPos], szTemp, 255);
				SendMessage(GetDlgItem(hWnd, IDC_FRDATA), TDM_SETTEXT, 0, (LPARAM)szTemp);
			}
			return FALSE;
		}

		adgHANDLE_DLGMSG(hWnd, WM_INITDIALOG, Shedul_OnInitDialog);
		adgHANDLE_DLGMSG(hWnd, WM_COMMAND, Shedul_OnCommand);
	}
	return FALSE;
}

void SetValue(HWND hWnd, LPSCHDATA lpSetData)
{
	SetDlgItemText(hWnd, IDC_EDIT4, lpSetData->szDesc);
	SetDlgItemText(hWnd, IDC_EDIT2, lpSetData->szPath);
	SetRtValue(hWnd, GetDlgItem(hWnd, IDC_FRDATA), GetDlgItem(hWnd, IDC_FRTIME), lpSetData->nFrecq);
	SendMessage(GetDlgItem(hWnd, IDC_CHECK1), BM_SETCHECK, !s_SchData.bEnable, 0);
	SendMessage(GetDlgItem(hWnd, IDC_HOTKEY1), HKM_SETHOTKEY, s_SchData.dwHotKey, 0);
}
