/*
+-----------------------------------------------------------------------------------------------------------------------+
|                                                                                                                       |
|          Program Name: WinLib.h                                                                                       |
|                Author: Michael Krämer                                                                                 |
|                        Michael@dk8pp.de               (private)                                                       |
|                  Date: 29-May-2011                                                                                    |
|              Language: Open Watcom C 1.9                                                                              |
|               Version: 1.1                                                                                            |
|        Program status: Release                                                                                        |
|                                                                                                                       |
+-----------------------------------------------------------------------------------------------------------------------+
|                                                                                                                       |
|  Purpose: Library with some often used functions for Windows programming                                              |
|                                                                                                                       |
|  History: V1.0, 30-Nov-2007: First public release                                                                     |
|           V1.1, 29-May-2011: Adaptation to stdint.h and stdbool.h, remove mytype.h                                    |
|                                                                                                                       |
+-----------------------------------------------------------------------------------------------------------------------+
*/
#ifndef WINLIB
#include <stdint.h>
#include "stdbool.h"

/*
+-----------------------------------------------------------------------------------------------------------------------+
|       Defines                                                                                                         |
+-----------------------------------------------------------------------------------------------------------------------+
*/
#define WINLIB 1
#define RESIZE_X 0x1            /* resize control in x direction */
#define RESIZE_Y 0x2            /* resize control in y direction */
#define MOVE_X   0x4            /* move control in x direction */
#define MOVE_Y   0x8            /* move control in y direction */
#define MY_REG_KEY_ROOT "Software\\Michael Krämer Freeware\\" /* Root for registry keys under HKEY_CURRENT_USER */
#define PARM_SIMPLE 1000        /* simple parameter, no argument (eg. -a, -rc etc.) */
#define PARM_INT 1001           /* integer parameter (eg. -q=-25) */
#define PARM_STRING 1002        /* string parameter (eg. -f=image.jpg, -f="c:\Program Files\image.jpg") */
#define PARM_POS 1003           /* positional parameter (eg. image.jpg, "c:\Program Files\image.jpg") */
#define MAXPARMLENGTH 128       /* maximum length of a command line parameter */
#define INI_NO 0                /* no initialization data */
#define INI_REGREAD   1         /* read registry */
#define INI_REGWRITE  2         /* write registry */
#define INI_FILEREAD  4         /* read initialization file */
#define INI_FILEWRITE 8         /* write initialization file */
#define REGFLAG_NONE 0          /* no flag */
#define REGFLAG_WRITEBACK 1     /* this registry entry is updated when the program executes and written back when it terminates */
#define REGFLAG_ARRAY  0x10000  /* this registry entry is an array of uint32_t */
#define REGFLAG_HEX    0x20000  /* read and write as a hex number */
#define REGFLAG_SIGNED 0x40000  /* read and write as a int32_t */

/*
+-----------------------------------------------------------------------------------------------------------------------+
|       structs and enums                                                                                               |
+-----------------------------------------------------------------------------------------------------------------------+
*/
typedef struct {
        uint32_t control ;
        uint32_t left ;
        uint32_t top ;
        uint32_t right ;
        uint32_t bottom ;
        uint32_t flags ;
                } COORDS ;

typedef struct { /* new, works with registry or ini-file */
        char *sectionname ;     /* points to the name of the section */
        char *valuename ;       /* points to the name of the value */
        uint32_t valuetype ;    /* type of the value */
        uint32_t flags ;        /* optional flags, see REGFLAG_ */
        void *value ;           /* points to the value */
        uint32_t valuesize ;    /* size of the value for type REG_MULTI_SZ (in number of bytes).
                                   Number of words for REG_DWORD&REGFLAG_ARRAY (should be 1 for REG_DWORD) */
                } INIVALUE ;

typedef struct { /* new, works with registry or ini-file */
        HKEY hkey ;             /* handle of open key */
        char *inikeyname ;      /* pointer to name of initialization key */
        char *inifilename ;     /* pointer to name of ini-file */
        INIVALUE *inivalues ;   /* pointer to the array of INIVALUEs */
        uint32_t initype ;      /* type of initialization (i.e. registry or ini-file) */
        uint32_t size ;
                } MYINI ;

typedef struct { /* command line options */
        char *parmname ;        /* name of parameter without leading "-" or "/" */
        uint32_t parmtype ;     /* type of this parameter */
        void *dest ;            /* pointer to destination for a string parameter */
        int32_t value ;         /* value of this parameter or maximum stringlength in case of a string */
        bool found ;            /* parameter was found */
        char *help ;            /* help text for this parameter */
                } CLO ;

/*
+-----------------------------------------------------------------------------------------------------------------------+
|       global variables                                                                                                |
+-----------------------------------------------------------------------------------------------------------------------+
*/

/*
+-----------------------------------------------------------------------------------------------------------------------+
|       Function prototypes                                                                                             |
+-----------------------------------------------------------------------------------------------------------------------+
*/
void display_info(char *msg) ;
void ShowError(int dialog) ;
void ShowSystemError(int errnr, int dialog) ;
void resize_controls(COORDS *coordinates, uint32_t size) ;
void get_coords(COORDS *coordinates, uint32_t size) ;
int32_t compare_hup(const void *op1, const void *op2) ;
int32_t compare_hdown(const void *op1, const void *op2) ;
int32_t compare_vup(const void *op1, const void *op2) ;
int32_t compare_vdown(const void *op1, const void *op2) ;
uint32_t WinLibMessage(unsigned msg, WPARAM wparam, LPARAM lparam) ;
void SaveCoordinates(void) ;
bool get_registry(MYINI *myreg) ;
void put_registry(MYINI *myreg) ;
void clear_registry(MYINI *myreg) ;
void PrintProgramInfo(uint32_t dlgitem, char *programname, char *date, char *time) ;
void getparms(LPSTR cmdline, char *errorparm) ;
void set_process_prio(int32_t prio) ;
void set_thread_prio(HANDLE hthread, int32_t prio) ;

#endif

