cbgui.c File Reference

WIN32 GUI. More...

#include <windows.h>
#include <commdlg.h>
#include <stdio.h>
#include <shlobj.h>
#include <math.h>
#include <stdlib.h>
#include "cbgps.h"
#include "cbrc.h"
#include "cbgpx.h"
#include <string.h>

Data Structures

struct  _config
 Present configuration of the program. More...
struct  _cbsientry
 One configuration entry in the list of entries set in the serial port information callback. More...
struct  _cbsictx
 Context for the serial port information callback. More...
struct  _gpscbcontrols
 Window handles of controls to fill with current coordinates. More...

Defines

#define MAX_STR_LEN   127
 Maximal string length, withou tthe trailing 0.
#define CFG_STR_LEN   31
 Length of an configuration item.
#define VAL_STR_LEN   15
 Length of the string for a value retrieved by the GPS callback.
#define SPRTF   _snprintf
#define MENU_START_ENABLED   1
#define MENU_STOP_ENABLED   2
#define MENU_CONFIG_ENABLED   4
#define MENU_GPXSTART_ENABLED   8
#define MENU_GPXSTOP_ENABLED   16
#define MENU_EXIT_ENABLED   32
#define MENU_ALL_ENABLED   ~0
#define WM_CBSIREADY   WM_USER + 1234
 Message sent to the configuration window after the serial info callback is ready.
#define WM_NEWCOORD   WM_USER + 1235
 Message sent to the main window, if new coordinates arrived.
#define COORD_UTC   0x0001
 Bitwise information, that UTC time changed.
#define COORD_ALT   0x0002
 Bitwise information, that the altitude changed.
#define COORD_LAT   0x0004
 Bitwise information, that latitude changed.
#define COORD_LON   0x0008
 Bitwise information, that longitude changed.
#define COORD_UTMN   0x0010
 Bitwise information, that UTM northing changed.
#define COORD_UTME   0x0020
 Bitwise information, that UTM easting changed.
#define ENMENU(enmask, flag)
 Creates the value for enabling or disabling a menu item depending on the given flag and mask.

Functions

static void _fmtErrMsg ()
 Pronts last system error in a message box.
static void _cbsientry_release (struct _cbsientry *first)
 Releases memory occupied by the list of serial port informations.
static void _cbserinfocb (const char *aName, CBSERINFO aType, void *aCtx)
 Callback function for serial port information.
static void _gpscb (double anUTC, double anNLat, double anELon, double anAlt, double aUTMN, double aUTME, void *aCtx)
 Callback routine retrieving current coordinates.
static void _popupmenu (HWND hwnd, int x, int y, int enabled)
 Shows a popup menu at the given position.
static short _dlggpxfilename (HWND hwnd, TCHAR *theFileName, size_t aLen)
 Opens common dialog for selecting the gpx file to create.
static BOOL CALLBACK _cfgdlgproc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
 Configuration dialog procedure.
static void _cfgfilename (TCHAR *theFileName)
 Builds the configuration file name. The configuration file name is [ApplicationData]\[_APPNAME].cfg, if not compiled with -DUSE_ENV, else it is $HOME/[_APPNAME].cfg.
static void _rdcfg (struct _config *aCfg)
 Reads configuration from a file into the given config structure.
static void _wrcfg (const struct _config *aCfg)
 Writes configuration to the configuration file.
static LRESULT CALLBACK _wndproc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
 The standard MS Windows window procedure.
static HMODULE _nlsresmod (HMODULE defHandle)
 Returns module handle for the resource dll responsible for the current locale.
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
 The main function of the application.

Variables

static const TCHAR _APPNAME [] = TEXT("cb")
static TCHAR _szQuit [MAX_STR_LEN+1]
static TCHAR _szOpenErr [MAX_STR_LEN+1]
static TCHAR _szCloseErr [MAX_STR_LEN+1]
static TCHAR _szFmtUTC [VAL_STR_LEN+1]
static TCHAR _szFmtNLat [VAL_STR_LEN+1]
static TCHAR _szFmtSLat [VAL_STR_LEN+1]
static TCHAR _szFmtELon [VAL_STR_LEN+1]
static TCHAR _szFmtWLon [VAL_STR_LEN+1]
static TCHAR _szFmtAlt [VAL_STR_LEN+1]
static TCHAR _szFmtUTME [VAL_STR_LEN+1]
static TCHAR _szFmtUTMN [VAL_STR_LEN+1]
static TCHAR _szGPXFilter [MAX_STR_LEN+1]
static HMODULE _hresmod
 Module for loading localized resources.


Detailed Description

WIN32 GUI.


Define Documentation

#define CFG_STR_LEN   31

Length of an configuration item.

A configuration item is for example the name of the COM port, baud rate, number of databits etc.

#define COORD_ALT   0x0002

Bitwise information, that the altitude changed.

#define COORD_LAT   0x0004

Bitwise information, that latitude changed.

#define COORD_LON   0x0008

Bitwise information, that longitude changed.

#define COORD_UTC   0x0001

Bitwise information, that UTC time changed.

#define COORD_UTME   0x0020

Bitwise information, that UTM easting changed.

#define COORD_UTMN   0x0010

Bitwise information, that UTM northing changed.

#define ENMENU ( enmask,
flag   ) 

Value:

(((enmask) & (flag)) == (flag))? (MF_BYCOMMAND | MF_ENABLED) :\
                                  (MF_BYCOMMAND | MF_GRAYED)
Creates the value for enabling or disabling a menu item depending on the given flag and mask.

Parameters:
enmask the bitwise mask of currently enabled menu items.
flag eg. MENU_START_ENABLED, MENU_STOP_ENABLED etc.

#define MAX_STR_LEN   127

Maximal string length, withou tthe trailing 0.

#define MENU_ALL_ENABLED   ~0

#define MENU_CONFIG_ENABLED   4

#define MENU_EXIT_ENABLED   32

#define MENU_GPXSTART_ENABLED   8

#define MENU_GPXSTOP_ENABLED   16

#define MENU_START_ENABLED   1

#define MENU_STOP_ENABLED   2

#define SPRTF   _snprintf

#define VAL_STR_LEN   15

Length of the string for a value retrieved by the GPS callback.

#define WM_CBSIREADY   WM_USER + 1234

Message sent to the configuration window after the serial info callback is ready.

#define WM_NEWCOORD   WM_USER + 1235

Message sent to the main window, if new coordinates arrived.

Message is sent in _gpscb() to the main window with a bitwise combination of the COORD_ constants in wParam.


Function Documentation

static void _cbserinfocb ( const char *  aName,
CBSERINFO  aType,
void *  aCtx 
) [static]

Callback function for serial port information.

Called for each available serial port parameter item: serial port name, baud, number of databits, parity, stopbits.

Parameters:
aName the name of the setting, eg. name of the serial port, number of databits, stopbits as string, parity or baudrate name. It may be also NULL!
aType type of the information in aName. For CBSI_BAUDRATE, CBSI_DATABITS, CBSI_PARITY, CBSI_STOPBITS, CBSI_SERIALPORT the values of aName and aType is added to the list of values. For CBSI_READY the configuration window is informed (PostMessage, WM_CBSIREADY), that it may put the informations into the controls.
aCtx casted to struct _cbsictx.

static void _cbsientry_release ( struct _cbsientry first  )  [static]

Releases memory occupied by the list of serial port informations.

Such a list is build in _cbserinfocb() and it should be released, if not needed anymore, eg. after the message WM_CBSIREADY has been sent.

Parameters:
first begin of the list to release

static BOOL CALLBACK _cfgdlgproc ( HWND  hwnd,
UINT  message,
WPARAM  wParam,
LPARAM  lParam 
) [static]

Configuration dialog procedure.

Puts the presently configured values into the controls of the dialog. If the dialog box has been closed using the OK button, then it puts the values from the controls back into the current configuration. The current configuration structure is expected under lParam.

Parameters:
hwnd the handle of the configuration dialog
message the windows message, WM_INITDIALOH, WM_COMMAND and WM_CBSIREADY are handled in this procedure.
wParam the procedure expects here the ID of the button pressed (IDOK, IDCANCEL) on WM_COMMAND.
lParam the pointer to struct _config containing the current configuration is expected here for WM_INITDIALOG.
Returns:
TRUE for WM_INITDIALOG and WM_COMMAND, FALSE else.

static void _cfgfilename ( TCHAR *  theFileName  )  [static]

Builds the configuration file name. The configuration file name is [ApplicationData]\[_APPNAME].cfg, if not compiled with -DUSE_ENV, else it is $HOME/[_APPNAME].cfg.

Parameters:
theFileName buffer for the resulting file name, must be able to hold at least MAX_PATH+1 characters.

static short _dlggpxfilename ( HWND  hwnd,
TCHAR *  theFileName,
size_t  aLen 
) [static]

Opens common dialog for selecting the gpx file to create.

Parameters:
hwnd the window owning the common dialog for selecting the file name.
theFileName buffer where to put the selected file name.
aLen lenght of the buffer.
Returns:
!=0 if the user selected a file name, 0 else or on error.

static void _fmtErrMsg (  )  [static]

Pronts last system error in a message box.

static void _gpscb ( double  anUTC,
double  anNLat,
double  anELon,
double  anAlt,
double  aUTMN,
double  aUTME,
void *  aCtx 
) [static]

Callback routine retrieving current coordinates.

Prepares WM_NEWCOORD message and new coordinates in text format in the context. Sending WM_NEWCOORD to the main window causes showing new coordinates in the controls.

Parameters:
anUTC the UTC time,
anNLat the latitude, positive for North, negative for South.
anELon the longitude, positive for East, negative for West.
anAlt the altitude in meters.
aUTMN the UTM northing in kilometers.
aUTME the UTM easting in kilometers.
aCtx casted to struct _gpscbcontrols.

static HMODULE _nlsresmod ( HMODULE  defHandle  )  [static]

Returns module handle for the resource dll responsible for the current locale.

The function looks for resource DLLs having the directory of the current executable plus filename of the executable plus a 4 digit hex number ID of the language + extension dll. The language ID according to the return value of GetUserDefaultLangID or GetSystemDefaultLangID (eg. 0407 hex for DE, 0409 hex for EN, 0415 hex for PL). If the DLL with the appropriate name has been found, the the function loads this DLL using LoadLibrary and returns the handle of it. If no suitable DLLs have been found for the user or system default laungage ID, then GetModuleHandle(NULL) (the handle of the exe) is returned meaning, that the application has to use the default locales.

Example of the dll file name for the locale:

  1. current executable located in c:\/emp/cb.exe
  2. name of the locale resource DLL for Polish c:/temp/cb0415.dll
  3. name of the locale resource DLL for German c:/temp/cb0407.dll

Wondering, why not for wine? Wine doesn't need this complicated way of localized resource dll loading. We can put all localized resources into one rc file and wine will automatically select the proper resource for the current system language in the environment variable LANG. This is because wine properly sets GetUser/SystemDefaultUILanguage() and windows doesn't. The default UI language in windows is this one, which you buyed in windows: spanish windows - spanish UI.

Parameters:
defHandle the default handle to return, if the DLLs have not been found.
Returns:
the handle of the module for resources to use with current locales.

static void _popupmenu ( HWND  hwnd,
int  x,
int  y,
int  enabled 
) [static]

Shows a popup menu at the given position.

Parameters:
hwnd the window, within which to display the menu.
x the x position
y the y position
enabled bitwise mask of enabled menu items

static void _rdcfg ( struct _config aCfg  )  [static]

Reads configuration from a file into the given config structure.

If the file doesn't exist or if reading the configuration fails for some reason, then the configuration structure is filled with plausible defaults.

Parameters:
aCfg pointer to the configuration structure.
See also:
_cfgfilename()

static LRESULT CALLBACK _wndproc ( HWND  hwnd,
UINT  message,
WPARAM  wParam,
LPARAM  lParam 
) [static]

The standard MS Windows window procedure.

On WM_INITDIALOG the function initialozes internal data structure: it reads the current configuration from the configuration file into a variable of type struct _config, initializes the GPS handle etc. On WM_COMMAND it handles the menu items pressed: starts the GPS reading thread on M_START, stops it on M_STOP, starts the configuration dialog on M_CFG or exits the application on M_EXIT.

Parameters:
hwnd the handle of the window
message window message, WM_INITDIALOG, WM_COMMAND, WM_CLOSE, WM_LBUTTONDOWN, WM_RBUTTONDOWN.
wParam message parameter, on WM_COMMAND M_START, M_STOP, M_CFG or M_EXIT are handled here.
lParam message parameter, ignored.
Returns:
0, if the procedure handles the given message by itself, return value of DefWindowProc() else

static void _wrcfg ( const struct _config aCfg  )  [static]

Writes configuration to the configuration file.

The configuration file name is always [ApplicationData]\[_APPNAME].cfg.

Parameters:
aCfg pointer to the configuration structure.
See also:
_cfgfilename()

int WINAPI WinMain ( HINSTANCE  hInstance,
HINSTANCE  hPrevInstance,
PSTR  szCmdLine,
int  iCmdShow 
)

The main function of the application.

Sets the dialog cbmain as the main window and _wndproc as the window procedure.

Parameters:
hInstance the handle of the instance.
hPrevInstance ignored.
szCmdLine ignored.
iCmdShow needed for ShowWindow.


Variable Documentation

const TCHAR _APPNAME[] = TEXT("cb") [static]

HMODULE _hresmod [static]

Module for loading localized resources.

Estimated using _nlsresmod().

TCHAR _szCloseErr[MAX_STR_LEN+1] [static]

TCHAR _szFmtAlt[VAL_STR_LEN+1] [static]

TCHAR _szFmtELon[VAL_STR_LEN+1] [static]

TCHAR _szFmtNLat[VAL_STR_LEN+1] [static]

TCHAR _szFmtSLat[VAL_STR_LEN+1] [static]

TCHAR _szFmtUTC[VAL_STR_LEN+1] [static]

TCHAR _szFmtUTME[VAL_STR_LEN+1] [static]

TCHAR _szFmtUTMN[VAL_STR_LEN+1] [static]

TCHAR _szFmtWLon[VAL_STR_LEN+1] [static]

TCHAR _szGPXFilter[MAX_STR_LEN+1] [static]

TCHAR _szOpenErr[MAX_STR_LEN+1] [static]

TCHAR _szQuit[MAX_STR_LEN+1] [static]


Generated on Thu Feb 12 11:09:26 2009 for cb by  doxygen 1.4.7