#include <windows.h>
#include <tchar.h>
#include "resource.h"

extern HWND g_hWnd;
extern BOOL labelsInToolbar;
extern BOOL timeInStatusbar;
extern BOOL loadAbcrc;
extern BOOL isWorking;
extern BOOL confirmExit;
extern BOOL SaveSettings(HWND hWnd);
extern void WithAppPath(char *fileName, char *fullFileName);
extern void CenterWindow(HWND hWnd);

/* Procedura dialogu Settings */
INT_PTR CALLBACK DialogSettings(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	char fullFileName[MAX_PATH];

	switch (uMsg)
	{
		case WM_COMMAND:
			switch (LOWORD(wParam))
			{
				case IDCANCEL:
					EndDialog(hwndDlg, IDCANCEL);
					break;
				case IDOK:
					labelsInToolbar = SendDlgItemMessage(hwndDlg, IDC_CHECK_LABELS, BM_GETCHECK, 0, 0);
					timeInStatusbar = SendDlgItemMessage(hwndDlg, IDC_CHECK_TIME, BM_GETCHECK, 0, 0);
					loadAbcrc = SendDlgItemMessage(hwndDlg, IDC_CHECK_LOAD, BM_GETCHECK, 0, 0);
					confirmExit = SendDlgItemMessage(hwndDlg, IDC_CHECK_CONFIRMEXIT, BM_GETCHECK, 0, 0);
					SaveSettings(hwndDlg);
					EndDialog(hwndDlg, IDOK);
					break;
				case IDC_BUTTON_EDIT_ABCRC:
					WithAppPath("abc.rc", fullFileName);					
					ShellExecute(hwndDlg, TEXT("open"), TEXT("notepad.exe"), fullFileName, NULL, SW_SHOW);
					break;
				case IDC_BUTTON_OUTPUT_SETTINGS:
					SendMessage(g_hWnd, WM_COMMAND, ID_PRINTSETTINGS, 0);
					break;
			}
			break;
		case WM_INITDIALOG:
			CenterWindow(hwndDlg);

			SendDlgItemMessage(hwndDlg, IDC_CHECK_LABELS, BM_SETCHECK, labelsInToolbar, 0);
			SendDlgItemMessage(hwndDlg, IDC_CHECK_TIME, BM_SETCHECK, timeInStatusbar, 0);
			SendDlgItemMessage(hwndDlg, IDC_CHECK_LOAD, BM_SETCHECK, loadAbcrc, 0);
			SendDlgItemMessage(hwndDlg, IDC_CHECK_CONFIRMEXIT, BM_SETCHECK, confirmExit, 0);

			if (isWorking)
			{
				EnableWindow(GetDlgItem(hwndDlg, IDC_CHECK_TIME), FALSE);
				EnableWindow(GetDlgItem(hwndDlg, IDC_BUTTON_OUTPUT_SETTINGS), FALSE);
			}

			break;
	}
	return FALSE;
}
