-
Notifications
You must be signed in to change notification settings - Fork 4
/
DLGUTIL.CPP
140 lines (133 loc) · 5 KB
/
DLGUTIL.CPP
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
//*******************************************************************
// D i a l o g B o x U t i l i t y F u n c t i o n s
//
// Copyright (c) 1995 - 1999 by John Coulthard
//
// This file is part of QuikGrid.
//
// QuikGrid is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// QuikGrid is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with QuikGrid (File gpl.txt); if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
// or visit their website at http://www.fsf.org/licensing/licenses/gpl.txt .
//
// Sept. 19/96: Modified to use "strtod" to do floating point
// conversions (Avoids need to use MS Service Pack 1).
// Sept. 23/98: Increased SetPrecision to 6 - part of conversion to
// WIN32 - conversions handled differently.
// Jan. 28/99: Alter Lat/Lon conversion to use mmddd.ddd format.
// (LatLonData=TRUE means data is Lat/Lon).
//*******************************************************************
#include <windows.h>
#include <iostream>
#include <strstream>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include "utilitys.h"
#include "assert.h"
#include "rc.h"
using namespace std;
extern int LatLonData;
//**********************************************************************
// R e p o r t N O S c o n v e r s i o n F a i l
//**********************************************************************
static void ReportNOSConversionFail( char szText[255] )
{
NotifyUser( IDS_LATLONERROR, szText );
}
//**********************************************************************
// S e t D l g I t e m F l o a t X Y
//**********************************************************************
void SetDlgItemFloatXY( HWND &hDlg, UINT Item, const double &x )
// Output number as metric or Lat/Lon formatted data.
{
static char szBuf[30];
FormatCoord( szBuf, sizeof(szBuf), x ) ;
SetDlgItemText( hDlg, Item, szBuf);
}
//**********************************************************************
// S e t D l g I t e m F l o a t
//**********************************************************************
void SetDlgItemFloat( HWND &hDlg, UINT Item, const double &x )
// Output Metric Floating point number only.
{
ostrstream Buf;
Buf << setprecision(6) << x << ends;
char *szBuf = Buf.str();
SetDlgItemText( hDlg, Item, szBuf);
delete szBuf;
}
//**********************************************************************
// S e t D l g I t e m L o n g
//**********************************************************************
void SetDlgItemLong( HWND &hDlg, UINT Item, const long &i )
// Output long integer number only.
{
ostrstream Buf;
Buf << i << ends;
char *szBuf = Buf.str();
SetDlgItemText( hDlg, Item, szBuf);
delete szBuf;
}
//**********************************************************************
// G e t D l g I t e m L o n g t i t u d e
//**********************************************************************
int GetDlgItemLongtitude( HWND &hDlg, UINT Item, double &result)
{
char szText[255];
GetDlgItemText( hDlg, Item, szText, sizeof( szText ) ) ;
if( !LonToDouble( result, szText ) )
{ ReportNOSConversionFail( szText ); return 1; }
return 0;
}
//**********************************************************************
// G e t D l g I t e m F l o a t X Y
//**********************************************************************
int GetDlgItemFloatXY( HWND &hDlg, UINT Item, double &result)
{
char szText[255], *endptr;
GetDlgItemText( hDlg, Item, szText, sizeof( szText ) ) ;
if( LatLonData )
{
if( !LatToDouble( result, szText ) )
{ ReportNOSConversionFail( szText ); return 1; }
}
else
{
result = strtod(szText, &endptr);
if( *endptr != NULL )
{
NotifyUser( IDS_FLOATINGPOINTERROR, szText );
result = 0;
return 1;
} // end if( *endptr....
} // end else
return 0;
}
//**********************************************************************
// G e t D l g I t e m F l o a t
//**********************************************************************
int GetDlgItemFloat( HWND &hDlg, UINT Item, double &result)
{
char szText[255], *endptr;
GetDlgItemText( hDlg, Item, szText, 255 ) ;
result = strtod(szText, &endptr);
if( *endptr != NULL )
{
NotifyUser( IDS_FLOATINGPOINTERROR, szText );
result = 0;
return 1;
}
return 0;
}