//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=--=-=-
//
//   Top-level include-file. Create a single class called EASY. Following the Windows tradition,
//   get all the "include-files" included in one top-level file.
//
#define _CRT_SECURE_NO_WARNINGS     // Get rid of bogus warning messages about sprintf()
#pragma comment(lib, "winmm.lib")	// For Windows sound
#include <windows.h>
#include <iostream>
#include <string.h>
#include <time.h>
#include <process.h>
#include "resource.h"


#define VERS_MAJOR          1           // Major software version number
#define VERS_MINOR          2           // Minor software version number

#define JACKPOT             0x0000003f  // 32-bit probability mask
#define MSG_BUF             0x100       // Maximum message string length
#define X_START             200
#define Y_START             100
#define WIN_WIDTH           804         // Main window width
#define WIN_HEIGHT          740         // Main window height
#define ABOUT_X_START       10          // Initial "about" box x-start
#define ABOUT_Y_START       10          // Initial "about" box y-start
#define ABOUT_WIDTH         220         // About-box width
#define ABOUT_HEIGHT        180         // About-box height
#define BUTTON_WIDTH        60          // Width of a button
#define BUTTON_HEIGHT       25          // Height of a button
#define ABOUT_WINDOW_WIDTH  250         // Overall "about" window width
#define ABOUT_WINDOW_HEIGHT 250         // Overall "about" window height
#define ABOUT_BUT_X_START   76          // Where to start the "Okay" button on the "About" window
#define ABOUT_BUT_Y_START   180         // Where to start the "Okay" button on the "About" window
#define CLK_NUM_HEIGHT      160         // Height of a numeral
#define CLK_NUM_WIDTH       79          // Zero based
#define CLK_HH_X_START      86          // Where to start all the numerals
#define CLK_HH_Y_START      490         // Where to start all the numerals
#define CLK_HL_X_START      (CLK_HH_X_START + CLK_NUM_WIDTH)
#define CLK_HL_Y_START      CLK_HH_Y_START
#define CLK_MH_X_START      (CLK_HL_X_START + (2 * CLK_NUM_WIDTH))
#define CLK_MH_Y_START      CLK_HH_Y_START
#define CLK_ML_X_START      (CLK_MH_X_START + CLK_NUM_WIDTH)
#define CLK_ML_Y_START      CLK_HH_Y_START
#define CLK_SH_X_START      (CLK_ML_X_START + (2 * CLK_NUM_WIDTH))
#define CLK_SH_Y_START      CLK_HH_Y_START
#define CLK_SL_X_START      (CLK_SH_X_START + CLK_NUM_WIDTH)
#define CLK_SL_Y_START      CLK_HH_Y_START
#define CLICK4_X_START      23
#define CLICK4_Y_START      530
#define CLICK4_WIDTH        33
#define CLICK4_HEIGHT       74
#define CLK_SP_X_START      744
#define CLK_SP_Y_START      CLICK4_Y_START
#define CLK_SP_WIDTH        CLICK4_WIDTH
#define CLK_SP_HEIGHT       CLICK4_HEIGHT

#define FAILURE -1
#define SUCCESS  0

//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=--=-=-
//
//   I put everything in a single class. Things that are to be initialized by the compiler, including
//    methods (functions), need to be static.
//
class EASY {

public:
    static int ClassMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow);
private:
//=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
//
//  CreateThread() is broken. It creates memory leaks. Newer versions should use _beginthreadex().
//  This macro resolves the problem with different 'C' runtime library versions. Keep this
//  private to this class.
//
#ifdef  _MT
typedef unsigned (__stdcall *PTHREAD_START) (void *);

#define START_THREAD(psa, StackSize, StartAddr, Param, CreateFlags, ThreadID) \
    ((HANDLE)_beginthreadex((void *)(psa), (unsigned)(StackSize), (PTHREAD_START)(StartAddr), \
    (void *)(Param), (unsigned)(CreateFlags), (unsigned *)(ThreadID)))
#else
#define START_THREAD CreateThread
#endif
//=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
//
//   More private macros
//

#define UNREFERENCED(x) ((void)(x))     // Parameters deliberately not referenced

#define MAKE_WINDOW(x, y, w, h, id) \
    CreateWindow(Easy.Static, NULL, WS_CHILD|WS_VISIBLE|SS_BITMAP|SS_NOTIFY, \
    (x), (y), (w), (h), hwnd,(HMENU) (id), Easy.wc.hInstance, NULL)

#define MAKE_WINDOW_QUIET(x, y, w, h, id) \
    CreateWindow(Easy.Static, NULL, WS_CHILD|WS_VISIBLE|SS_BITMAP, \
    (x), (y), (w), (h), hwnd,(HMENU) (id), Easy.wc.hInstance, NULL)

#define MAKE_BUTTON(x, y, w, h, id) \
    CreateWindow(Easy.Button, Easy.Okay, WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON, \
    (x), (y), (w), (h), hwnd,(HMENU) (id), Easy.wc.hInstance, NULL)

#define PAINT_WINDOW(handle, bits) \
    DeleteObject((HGDIOBJ)SendMessage((handle), STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)(HBITMAP) \
    LoadBitmap(Easy.wc.hInstance, MAKEINTRESOURCE((bits)))))

//=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

    enum ID_LABEL {ID_IM = 1, ID_AB, ID_HH, ID_HL, ID_MH, ID_ML, ID_SH, ID_SL, ID_SP, ID_CK };
    enum DIGIT {HRS, MIN, MINAM, MINPM, SEC};
    static LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
    static LRESULT CALLBACK AboutWindowProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam);
    static void Align2UpperLeft(HWND hwnd);
    static void onmenu(WPARAM wParam);
    static void ShowJackpot(void);
    static void UpdateRand(void);
    static void ReleaseDevice(void);
    static void AcquireDevice(void);
    static void DoTime(void);
	static void LocalSound(const char *fname);
	static void DisplayMessage(const char *msg,...);
    static void ChangeClock(BOOL sound);
    static void ShowDigit(enum DIGIT digit, int dec);
    static LRESULT Display(void *worthless);
    static LRESULT UploadAllBitmaps(void *worthless);
    static LRESULT MakeRandom(void *worthless);
    static int GetRand(void);
	static char *LastChar(char *str, int character);
    static class EASY Easy;
    static const char appName[];
    static const char Static[];
    static const char CopyRight[];
    static const char Okay[];
    static const char Button[];
    static const char AboutClass[];
    static const char Info[];
    static const char Error[];
	static const char Clicked[];
	static const char LoDigit[];
	static const char HiDigit[];
    static const long Digits[];
    static const long DigitsA[];
    static const long DigitsP[];
    static const long DigitsM[];
    static const int  Times[];
    LPDWORD ThreadId;
    WNDCLASS wc;
    HWND mainwin;
    HWND aboutwin;
    HWND abouthan;
    HWND buttnhan;
    HWND mi;
    HWND hh;
    HWND hl;
    HWND mh;
    HWND ml;
    HWND sh;
    HWND sl;
    HWND ck;
    HWND sp;
    HANDLE Clock;
    MSG Msg;
	char *Exepath;
    char *Heading;
    BOOL hr12;
protected:
    int Rand;
    LONG SharedDevice;
};
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=--=-=-
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=--=-=-
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=--=-=-
