// Using Microsoft's Visual Studio 2008 C++. In Project -Time Properties -Configuration Properties, put winmm.lib in -Linker -Input -Additional Dependencies
#include <windows.h>
#include <math.h>
#include <mmsystem.h> // add winmm.lib to Project -Settings -Link (or (in Visual Studio 2005) Project -Properties -Configuration Properties -Linker -Input)
#include "resource.h"
#define GREY 0xFFFFFF
#define RED 0xFF
#define RADIUS 3
#define TIMER_RESOLUTION 1
#define PI 3.141592653589793
#define DEG2RAD 0.017453292519943295 // PI/180.0
#define RAD2DEG 57.295779513082323 // 180.0/PI

char Help[] = "Press  S  a  n  d  T  e  s  t  or  ?";
char Help2[] = "Change background color by holding down: R r G g B or b";
//char Help3[] = "(Caps Lock won't work)";
char szAppName[] = "  S  a  n  d  T  e  s  t  ?";
char IniFile[] = "C:\\USERS\\Public\\Time.ini";
char TimesNewRoman[] = TEXT("Times New Roman");
char timer1[] = "Click on the clock's 1 thru 12 o'clock circle";
char timer2[] = "to start a countdown of 1 thru 12 minutes.";
char Timer1[] = "Click on the clock's 1 thru 60 minute circle";
char Timer2[] = "to start a countdown of 1 thru 60 minutes.";
char Hour1[] = "Click within the alarm HOUR.";
char Minute1[] = "Click on the alarm MINUTE.";
char Time[] = "00:00";
int x, y, ScreenWidth, ScreenHeight, Menu, Left, Top, centerX, centerY, horiz, vert, SecondsRadius;
int TimerSecs, TimerSecond, ElapsedSecs, AlarmHour, AlarmMinute, Hour0, Minute0, Second0, hour, minute, second;
DWORD color2, dwBytesRead, dwBytesWritten;
unsigned int uTimerID = 0;
WORD HourOffset, H;
double min, d, HourLength, MinuteLength, rad, deg, Deg, secs, dHour, dHour2, dMinute, MinuteLocationOfHour, SecondsLocationOfMinute;
float f;
bool first = true, alarm, date = true, seconds = false, minutes = false, timer = false, Timer = false, shiftpressed = false, numbers = false, elapsed = false, startedtimer = false;
bool Default = false, seconds2minutes = false, colorchange = false;
//bool DontShowszAppName = false;
char *DayOfWeek[7] = {"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};
char *Month[13] = {"","January","February","March","April","May","June","July","August","September","October","November","December"};
char *Day[32] = {"","1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31"};
char *Numbers[12] = {"3","4","5","6","7","8","9","10","11","12","1","2"};
char *Numbers2[12] = {"15","20","25","30","35","40","45","50","55","0","5","10"};
char ElapsedTime[] = "00:00:00";
int Twelve[] = {360,330,300,270,240,210,180,150,120,90,60,30,0};
HWND hwnd;
HANDLE hFile;
HDC hdc, hdcMem;
HBITMAP hBitmap;
PAINTSTRUCT ps;
RECT rect;
HFONT hFont;
HPEN hPen, hRedPen;
HGDIOBJ hOldPen, hOldFont;
HBRUSH hBrush, hClockBrush;
POINT point;
SYSTEMTIME SystemTime;
LOGFONT lf;
SIZE size;
COLORREF color = 0x6b680d; // default is 0x6b680d (hardly any red)

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{
	MSG          msg;
	WNDCLASS     wndclass;

	wndclass.style         = CS_HREDRAW|CS_VREDRAW;
	wndclass.lpfnWndProc   = WndProc;
	wndclass.cbClsExtra    = 0;
	wndclass.cbWndExtra    = 0;
	wndclass.hInstance     = hInstance;
	wndclass.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
	wndclass.hCursor       = LoadCursor(NULL, IDC_ARROW);
	wndclass.hbrBackground = hBrush;
	wndclass.lpszMenuName  = NULL;
	wndclass.lpszClassName = szAppName;

	if (!RegisterClass(&wndclass))
		return 0;

	hwnd = CreateWindow(szAppName, szAppName,
		WS_CAPTION | WS_SYSMENU,
		0,0,0,0,
		NULL, NULL, hInstance, NULL);

	ShowWindow(hwnd, iCmdShow); // SW_SHOW);
	UpdateWindow(hwnd);

	while (GetMessage(&msg, NULL, 0, 0))
	{
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}
	return msg.wParam;
}

void drawcircle(int x0, int y0, int radius)
{
    int x = radius;
    int y = 0;
    int err = 0;

    while (x >= y)
    {
        SetPixel(hdcMem, x0 + x, y0 + y, GREY);
        SetPixel(hdcMem, x0 + y, y0 + x, GREY);
        SetPixel(hdcMem, x0 - y, y0 + x, GREY);
        SetPixel(hdcMem, x0 - x, y0 + y, GREY);
        SetPixel(hdcMem, x0 - x, y0 - y, GREY);
        SetPixel(hdcMem, x0 - y, y0 - x, GREY);
        SetPixel(hdcMem, x0 + y, y0 - x, GREY);
        SetPixel(hdcMem, x0 + x, y0 - y, GREY);
        y += 1;
        err += 1 + (2*y);
        if (2*(err-x) + 1 > 0) {
            x -= 1;
            err += 1 - (2*x);
        }
    }
}

void CALLBACK TimerFunc(UINT uID, UINT uMsg, DWORD dwUser, DWORD dw1, DWORD dw2)
{ // called every second from WM_PAINT
/*	if (DontShowszAppName) {
		H = SystemTime.wHour;
		if (H >= 12)
			H -= 12;
		if (H < 10)
			Time[0] = ' ';
		else
			Time[0] = (SystemTime.wHour / 10) + '0';
		Time[1] = (SystemTime.wHour % 10) + '0';
		Time[3] = (SystemTime.wMinute / 10) + '0';
		Time[4] = (SystemTime.wMinute % 10) + '0';
		SetWindowText(hwnd, Time);
	}*/
	InvalidateRect(hwnd, &rect, FALSE);
}

void ChangeBackground(void)
{
	colorchange = true;
	DeleteObject(hBrush);
	hBrush = CreateSolidBrush(color); // WHITE is changed background color from VK_UP or VK_DOWN
	FillRect(hdcMem, &rect, hBrush);
	InvalidateRect(hwnd, &rect, FALSE);
}

LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	switch(message)
	{
	case WM_CREATE:
		lf.lfHeight = -90;
		lf.lfWeight = 400;
		lf.lfItalic = 0;
		lf.lfUnderline = 0;
		lf.lfStrikeOut = 0;
		lf.lfCharSet = 0;
		lf.lfOutPrecision = 3;
		lf.lfClipPrecision = 2;
		lf.lfQuality = 1;
		lf.lfPitchAndFamily = 0x12;
		for (x = 0; TimesNewRoman[x] != 0; x++)
			lf.lfFaceName[x] = TimesNewRoman[x];
		lf.lfFaceName[x] = 0;
		hFont = CreateFontIndirect(&lf);
//		SystemParametersInfo(SPI_GETWORKAREA, 0, &ScreenRect, 0);
		ScreenWidth = GetSystemMetrics(SM_CXFULLSCREEN);
		ScreenHeight = GetSystemMetrics(SM_CYFULLSCREEN);
		Menu = GetSystemMetrics(SM_CYCAPTION);
		Left = (ScreenWidth/2)-(610/2);
		Top = (ScreenHeight/2)-(635/2);
		MoveWindow(hwnd, Left, Top, 610, 635, FALSE);
		centerX = 300;
		centerY = 300;
		Deg = 361.1; // flag
		HourLength = 180.0; // length
		MinuteLength = 280.0; // length
		AlarmHour, AlarmMinute = 0xFFFF;
		alarm = false;
		hFile = CreateFile(IniFile, GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
		if (hFile != INVALID_HANDLE_VALUE) {
			ReadFile(hFile, &color2, 4, &dwBytesRead, NULL);
			CloseHandle(hFile);
			color = (COLORREF)color2;
		}
		hBrush = CreateSolidBrush(color);
		break;

	case WM_KEYDOWN:
		if (GetKeyState(VK_SHIFT) & 0x8000) shiftpressed = true;
		else shiftpressed = false;
		Default = false;
		switch (wParam)
		{
		case 'R':
			if (shiftpressed) {
				if ((color & 0xFF) < 0xFF) {
					color += 1;
					ChangeBackground();
				}
			}
			else {
				if ((color & 0xFF) > 0) {
					color -= 1;
					ChangeBackground();
				}
			}
			break;
		case 'G':
			if (shiftpressed) {
				if (((color >> 8) & 0xFF) < 0xFF) {
					color += 0x100;
					ChangeBackground();
				}
			}
			else {
				if (((color >> 8) & 0xFF) > 0) {
					color -= 0x100;
					ChangeBackground();
				}
			}
			break;
		case 'B':
			if (shiftpressed) {
				if (((color >> 16) & 0xFF) < 0xFF) {
					color += 0x10000;
					ChangeBackground();
				}
			}
			else {
				if (((color >> 16) & 0xFF) > 0) {
					color -= 0x10000;
					ChangeBackground();
				}
			}
			break;
		case 'A':
			AlarmHour = 0xFFFF;
			AlarmMinute = 0xFFFF;
			if (alarm == false) {
				alarm = true;
				timer = false;
			}
			else {
				alarm = false;
				Deg = 361.1;
			}
			break;
		case 'D':
			if (date == false) {
				date = true;
			}
			else {
				date = false;
				Deg = 361.1;
			}
			break;
		case 'E':
			if (elapsed)
				elapsed = false;
			else {
				elapsed = true;
				GetLocalTime(&SystemTime);
				Second0 = SystemTime.wSecond;  // ((SystemTime.wSecond) + (60*SystemTime.wMinute) + (3600*SystemTime.wHour));
				Minute0 = SystemTime.wMinute;
				Hour0 = SystemTime.wHour;
			}
			ElapsedSecs = 0;
			break;
		case 'N':
			if (numbers == false)
				numbers = true;
			else
				numbers = false;
			break;
		case 'S':
			if (!shiftpressed) {
				SecondsRadius = 6;
				if (seconds == false) {
					seconds = true;
				}
				else {
					seconds = false;
					Deg = 361.1;
				}
			}
			else {
				if (minutes == false)
					minutes = true;
				else
					minutes = false;
			}
			break;
		case 'T':
			if (!shiftpressed) {
				if (timer == false) {
					timer = true;
					startedtimer = false;
					alarm = date = seconds = false;
				}
				else {
					timer = false;
					TimerSecs = 0;
					Deg = 361.1;
				}
			}
			else { // if (shiftpressed)
				if (Timer == false) {
					if (minutes == false)
						minutes = true;
					else
						minutes = false;

					Timer = true;
					startedtimer = false;
					alarm = date = seconds = false;
				}
				else {
					Timer = false;
					TimerSecs = 0;
					Deg = 361.1;
				}
			}
			break;
		case 191: // '/'
			if (shiftpressed) { // '?'
				if (seconds2minutes == false) {
					seconds2minutes = true;
					GetLocalTime(&SystemTime);
					HourOffset = SystemTime.wHour;
				}
				else
					seconds2minutes = false;
			}
			break;
		case VK_SPACE:
			alarm = date = seconds = timer = Timer = minutes = elapsed = seconds2minutes = false;
			numbers = false;
			TimerSecs = 0;
			Deg = 361.1;
			break;
		case VK_ESCAPE:
			DestroyWindow(hwnd);
			break;
		default:
			if (!shiftpressed)
				Default = true;
			break;
		}
		if (!Default)
			SetWindowText(hwnd, " ");
//		DontShowszAppName = true;
		break;

	case WM_LBUTTONDOWN: // to set alarm or timer
		GetCursorPos(&point);
		x = point.x-Left-300;
		y = point.y-Top-Menu-300;
		if (x && y) {
			d = ((double)y / (double)x);
			Deg = (atan(d) * RAD2DEG);
			if (x > 0)
				 Deg += 90.0;
			else if (x < 0)
				Deg += 270.0;
		}
		else if ((y == 0) && (x)) {
			if (x > 0)
				Deg = 90.0;
			else
				Deg = 270;
		}
		else if ((x == 0) && (y)) {
			if (y > 0)
				Deg = 180;
			else
				Deg = 360.0;
		}
		if (alarm) { // A
			if (0xFFFF == AlarmHour) {
				GetLocalTime(&SystemTime);
				dHour = Deg;
				f = (float)(Deg / 30.0); // necessary ???
				AlarmHour = (int)f;
				if (AlarmHour < SystemTime.wHour) {
					AlarmHour += 12;
					if ((AlarmHour >= 24) || (AlarmHour < SystemTime.wHour)) {
						MessageBox(hwnd, "The alarm won't work past midnight.", "Sorry", MB_OK);
						SendMessage(hwnd, WM_KEYDOWN, 'A', 0);
					}
				}
			}
			else if (0xFFFF == AlarmMinute) {
				GetLocalTime(&SystemTime);
				dMinute = Deg;
				f = (float)((Deg / 6.0) + 0.5);
				AlarmMinute = (int)f;
				dMinute = (double)(AlarmMinute * 6);
			}
		}
		else if ((Timer) && (!startedtimer)) { // T
			startedtimer = true;
			GetLocalTime(&SystemTime);
			TimerSecond = ((SystemTime.wSecond) + (60*SystemTime.wMinute) + (3600*SystemTime.wHour));
			secs = 10.0 * Deg; // 3600 seconds, 360 degrees
			TimerSecs = (int)(secs+0.5);
		}
//		if ((timer) && (!startedtimer)) { // t
		else {
timer = true;
startedtimer = false;
alarm = date = seconds = false;
			startedtimer = true;
			GetLocalTime(&SystemTime);
			TimerSecond = ((SystemTime.wSecond) + (60*SystemTime.wMinute) + (3600*SystemTime.wHour));
			secs = 2.0 * Deg; // 720 seconds, 360 degrees
			TimerSecs = (int)(secs+0.5);
//			modf(secs, &secs);
		}
		Deg = 361.1;
		break;

	case WM_PAINT:
		timeKillEvent(uTimerID);
		hdc = BeginPaint(hwnd, &ps);
		GetLocalTime(&SystemTime);
		if (first) {
			first = false;
			rect = ps.rcPaint;
			hdcMem = CreateCompatibleDC(hdc);
			hBitmap = CreateCompatibleBitmap(hdc, rect.right, rect.bottom);
			SelectObject(hdcMem, hBitmap);
			hClockBrush = CreateSolidBrush(GREY);
			hPen = CreatePen(PS_SOLID, 2, GREY);
			hRedPen = CreatePen(PS_SOLID, 2, RED);
			SetBkMode(hdcMem, TRANSPARENT);
			GetTextExtentPoint32(hdc, (LPCSTR)Month[SystemTime.wMonth], lstrlen(Month[SystemTime.wMonth]), &size); // for where to put the date just after the month
		}
		SelectObject(hdcMem, hPen);
		FillRect(hdcMem, &rect, hBrush);
		SelectObject(hdcMem, hClockBrush);

		if (!seconds2minutes) {
			if (!minutes)
				deg = (double)SystemTime.wMinute * 6.0;
			else { // if (minutes)
				for (deg = 0.0; deg < 360.0; deg += 6.0) { // second lines
					rad = deg * DEG2RAD;
					vert = int(290 * sin(rad)); // 283
					horiz = int(290 * cos(rad));
					if (((int)deg % 30) != 0) // 6, 12, 18, 24, 30, 36,
						Ellipse(hdcMem, centerX+horiz-1, centerY+vert-1, centerX+horiz+1, centerY+vert+1);
					else
						Ellipse(hdcMem, centerX+horiz-RADIUS, centerY+vert-RADIUS, centerX+horiz+RADIUS, centerY+vert+RADIUS);
				}
				SecondsLocationOfMinute = ((double)SystemTime.wSecond / 10.0);
				deg = ((double)SystemTime.wMinute * 6.0) + SecondsLocationOfMinute;
			}
			deg -= 90.0; // necessary;
			rad = deg * DEG2RAD;
			vert = (int)(MinuteLength * sin(rad));
			horiz = (int)(MinuteLength * cos(rad));
			MoveToEx(hdcMem, centerX, centerY, 0);
			LineTo(hdcMem, centerX+horiz, centerY+vert); // minute
			MinuteLocationOfHour = (double)SystemTime.wHour*30.0;
			deg = MinuteLocationOfHour+(double)SystemTime.wMinute/2.0;
			deg -= 90.0; // necessary
			rad = deg * DEG2RAD;
			vert = int(HourLength * sin(rad));
			horiz = int(HourLength * cos(rad));
			MoveToEx(hdcMem, centerX, centerY, 0); // hour
			LineTo(hdcMem, centerX+horiz, centerY+vert);
		}
		else { // if (seconds2minutes) '?'
			for (deg = 0.0; deg < 360.0; deg += 6.0) { // second lines
				rad = deg * DEG2RAD;
				vert = int(290 * sin(rad)); // 283
				horiz = int(290 * cos(rad));
				if (((int)deg % 30) != 0) // 6, 12, 18, 24, 30, 36,
					Ellipse(hdcMem, centerX+horiz-1, centerY+vert-1, centerX+horiz+1, centerY+vert+1);
				else
					Ellipse(hdcMem, centerX+horiz-RADIUS, centerY+vert-RADIUS, centerX+horiz+RADIUS, centerY+vert+RADIUS);
			}

			deg = ((double)SystemTime.wSecond * 6.0);
			deg -= 90.0;
			rad = deg * DEG2RAD;
			vert = int(MinuteLength * sin(rad));
			horiz = int(MinuteLength * cos(rad));
			MoveToEx(hdcMem, centerX, centerY, 0);
			LineTo(hdcMem, centerX+horiz, centerY+vert); // minute
			if (SystemTime.wSecond == 0)
				HourOffset++;
			MinuteLocationOfHour = (double)HourOffset * 30.0;
			deg = MinuteLocationOfHour+(double)SystemTime.wSecond / 2.0;
			deg -= 90.0; // necessary
			rad = deg * DEG2RAD;
			vert = int(HourLength * sin(rad));
			horiz = int(HourLength * cos(rad));
			MoveToEx(hdcMem, centerX, centerY, 0); // hour
			LineTo(hdcMem, centerX+horiz, centerY+vert);
		}
		if ((!minutes) && (!seconds2minutes)) {
			drawcircle(centerX, centerY, 290);
			for (deg = 0.0; deg < 360.0; deg += 30.0) { // dots
				rad = deg * DEG2RAD;
				vert = int(290 * sin(rad));
				horiz = int(290 * cos(rad));
				Ellipse(hdcMem, centerX+horiz-RADIUS, centerY+vert-RADIUS, centerX+horiz+RADIUS, centerY+vert+RADIUS);
			}
		}
		if (alarm) {
			if (AlarmHour == 0xFFFF) {
				TextOut(hdcMem, 15, 290, Hour1, lstrlen(Hour1));
				if (Deg != 361.1)
					Deg = 361.1; // if WM_LBUTTONDOWN before 'A' pressed
			}
			else if (AlarmMinute == 0xFFFF)
				TextOut(hdcMem, 15, 310, Minute1, lstrlen(Minute1));
			else if ((AlarmHour <= SystemTime.wHour) && (AlarmMinute <= SystemTime.wMinute))
				PlaySound(NULL, NULL, SND_SYSTEM);
			else {
				y = (int)dHour;
				for (x = 0; (x < 13) && (y < Twelve[x]); x++)
					;
				d = (double)Twelve[x] + (dMinute/12.0);
				rad = (d-90.0) * DEG2RAD;
				vert = int(HourLength * sin(rad));
				horiz = int(HourLength * cos(rad));
				hOldPen = SelectObject(hdcMem, hRedPen);
				MoveToEx(hdcMem, centerX, centerY, 0); // hour
				LineTo(hdcMem, centerX+horiz, centerY+vert);
				rad = (dMinute-90.0) * DEG2RAD;
				vert = int(MinuteLength * sin(rad));
				horiz = int(MinuteLength * cos(rad));
				MoveToEx(hdcMem, centerX, centerY, 0); // hour
				LineTo(hdcMem, centerX+horiz, centerY+vert);
				SelectObject(hdcMem, hOldPen);
			}
		}
		if (date) {
			SetTextColor(hdcMem, GREY);
			TextOut(hdcMem, 280, 200, DayOfWeek[SystemTime.wDayOfWeek], strlen(DayOfWeek[SystemTime.wDayOfWeek]));
			TextOut(hdcMem, 280, 220, Month[SystemTime.wMonth], strlen(Month[SystemTime.wMonth]));
			TextOut(hdcMem, 280 + 10 + size.cx, 220, Day[SystemTime.wDay], strlen(Day[SystemTime.wDay]));
		}
		if (elapsed) {
			second = SystemTime.wSecond - Second0;
			minute = SystemTime.wMinute - Minute0;
			hour = SystemTime.wHour - Hour0;
			if (SystemTime.wSecond < Second0) {
				second += 60;
				minute--;
				if (minute < 0)
//					minute += 60;
					minute++;
			}
			if (SystemTime.wMinute < Minute0) {
				minute += 60;
				hour--;
				if (hour < 0)
//					hour += 12;
					hour++;
			}
			ElapsedTime[0] = (hour / 10) + '0';
			ElapsedTime[1] = (hour % 10) + '0';
			ElapsedTime[3] = (minute / 10) + '0';
			ElapsedTime[4] = (minute % 10) + '0';
			ElapsedTime[6] = (second / 10) + '0';
			ElapsedTime[7] = (second % 10) + '0';
			hOldFont = SelectObject(hdcMem, hFont);
			TextOut(hdcMem, 140, 300, ElapsedTime, 8);
			SelectObject(hdcMem, hOldFont);
		}
		if (numbers) { // "N"
			for (x = 0, deg = 0.0; deg < 360.0; deg += 30.0, x++) {
				rad = deg * DEG2RAD;
				vert = int(270 * sin(rad)) - 10;
				horiz = int(270 * cos(rad)) - 5;
				SetTextColor(hdcMem, 0xFFFFFF);
				TextOut(hdcMem, centerX+horiz, centerX+vert, Numbers2[x], 2); // minutes
				vert = int(180 * sin(rad)) - 10;
				horiz = int(180 * cos(rad)) - 5;
				TextOut(hdcMem, centerX+horiz, centerX+vert, Numbers[x], 2);
			}
//			for (deg = 0.0; deg < 360.0; deg += 6.0) { // minute dots
//				rad = deg * DEG2RAD;
//				vert = int(290 * sin(rad));
//				horiz = int(290 * cos(rad));
//				Ellipse(hdcMem, centerX+horiz-2, centerY+vert-2, centerX+horiz+2, centerY+vert+2);
//			}
		}
		if (seconds) {
			deg = SystemTime.wSecond*6;
			deg -= 90.0; // necessary...
			rad = deg * DEG2RAD;
			vert = int(283.0 * sin(rad)) + centerX;
			horiz = int(283.0 * cos(rad)) + centerX;
			Ellipse(hdcMem, horiz-SecondsRadius, vert-SecondsRadius, horiz+SecondsRadius, vert+SecondsRadius); // seconds dot
		}
		if ((timer) || (Timer)) { // Deg is for timer and deg for everything else
			if (TimerSecs) {
				ElapsedSecs = (TimerSecs + TimerSecond - (((SystemTime.wSecond) + (60*SystemTime.wMinute) + (3600*SystemTime.wHour))));
				if (ElapsedSecs > 0) {
					if (timer)
						Deg = (double)ElapsedSecs / 2.0; // 720 secs = 360 deg
					else // if (Timer)
						Deg = (double)ElapsedSecs / 10.0; // 3600 secs = 360 deg
					Deg -= 90.0; // necessary...
				}
				else {
					Deg = 270.0; // keep timer dot at 0
					PlaySound("timer.wav", NULL, SND_FILENAME);
				}
				rad = Deg * DEG2RAD;
				vert = int(290.0 * sin(rad)) + centerX;
				horiz = int(290.0 * cos(rad)) + centerX;
				if (timer)
					Ellipse(hdcMem, horiz-10, vert-10, horiz+10, vert+10);
				else { // if (Timer)
					Ellipse(hdcMem, horiz-6, vert-6, horiz+6, vert+6);
					for (x = 0, deg = 0.0; deg < 360.0; deg += 30.0, x++) {
						rad = deg * DEG2RAD;
						vert = int(270 * sin(rad)) - 10;
						horiz = int(270 * cos(rad)) - 5;
						TextOut(hdcMem, centerX+horiz, centerX+vert, Numbers2[x], 2); // minutes
					}
				}
			}
			else { // if (TimerSecs == 0)
				if (timer) {
					TextOut(hdcMem, 20, 290, timer1, lstrlen(timer1));
					TextOut(hdcMem, 20, 310, timer2, lstrlen(timer2));
				}
				else { // if (Timer)
					for (x = 0, deg = 0.0; deg < 360.0; deg += 30.0, x++) {
						rad = deg * DEG2RAD;
						vert = int(270 * sin(rad)) - 10;
						horiz = int(270 * cos(rad)) - 5;
						SetTextColor(hdcMem, 0xFFFFFF);
						TextOut(hdcMem, centerX+horiz, centerX+vert, Numbers2[x], 2); // minutes
					}
					TextOut(hdcMem, 60, 290, Timer1, lstrlen(Timer1));
					TextOut(hdcMem, 60, 310, Timer2, lstrlen(Timer2));
				}
			}
		}
		if (Default) {
			TextOut(hdcMem, 60, 290, Help, lstrlen(Help));
			TextOut(hdcMem, 60, 310, Help2, lstrlen(Help2));
//			TextOut(hdcMem, 60, 330, Help3, lstrlen(Help3));
		}
		BitBlt(hdc, 0, 0, rect.right, rect.bottom, hdcMem, 0, 0, SRCCOPY);
		EndPaint(hwnd, &ps);
		uTimerID = timeSetEvent(1000-SystemTime.wMilliseconds, TIMER_RESOLUTION, (LPTIMECALLBACK)TimerFunc, 0, TIME_ONESHOT); // every second
		break;

	case WM_DESTROY:
		if ((colorchange) && ((IDYES == MessageBox(hwnd, "Save color changes to C:\\\\users\\Public\\Time.ini?", "", MB_YESNO)))) {
			hFile = CreateFile(IniFile, GENERIC_READ|GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
			if (hFile != INVALID_HANDLE_VALUE) {
				color2 = (DWORD)color;
				WriteFile(hFile, &color2, 4, &dwBytesWritten, NULL);
				CloseHandle(hFile);
			}
		}
		SetBkMode(hdcMem, OPAQUE);
		PostQuitMessage(0);
		break;
	}
	return DefWindowProc(hwnd, message, wParam, lParam);
}
