-
Notifications
You must be signed in to change notification settings - Fork 0
/
FormatNums.cpp
102 lines (84 loc) · 2.25 KB
/
FormatNums.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
/*-----------------------------------------------------------------------------
6502 Macroassembler and Simulator
Copyright (C) 1995-2003 Michal Kowalski
This program 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.
This program 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 this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-----------------------------------------------------------------------------*/
#include "stdafx.h"
#include "FormatNums.h"
void CFormatNums::IncEditField(CWnd *pCtrl, int iDelta, int iMin, int iMax)
{
int num,old;
NumFmt fmt;
old = num = ReadNumber(pCtrl,fmt);
num += iDelta;
if (num > iMax)
num = iMax;
else if (num < iMin)
num = iMin;
if (num != old)
SetNumber(pCtrl,num,fmt);
}
int CFormatNums::ReadNumber(CWnd *pCtrl, NumFmt &fmt)
{
TCHAR buf[32];
int num= 0;
if (pCtrl==NULL)
return num;
pCtrl->GetWindowText(buf,sizeof(buf)/sizeof(buf[0]));
if (buf[0]==_T('$'))
{
fmt = NUM_HEX_DOL;
if (sscanf(buf+1, _T("%X"),&num) <= 0)
{}
}
else if (buf[0]==_T('0') && (buf[1]==_T('x') || buf[1]==_T('X')))
{
fmt = NUM_HEX_0X;
if (sscanf(buf+2, _T("%X"),&num) <= 0)
{}
}
else if (buf[0]>=_T('0') && buf[0]<=_T('9'))
{
fmt = NUM_DEC;
if (sscanf(buf, _T("%d"),&num) <= 0)
{}
}
else
fmt = NUM_ERR;
return num;
}
void CFormatNums::SetNumber(CWnd *pCtrl, int num, NumFmt fmt)
{
TCHAR buf[32];
buf[0] = 0;
switch (fmt)
{
case NUM_ERR:
case NUM_HEX_0X:
wsprintf(buf,_T("0x%04X"),num);
break;
case NUM_HEX_DOL:
wsprintf(buf,_T("$%04X"),num);
break;
case NUM_DEC:
wsprintf(buf,_T("%d"),num);
break;
default:
ASSERT(FALSE);
}
if (pCtrl)
{
pCtrl->SetWindowText(buf);
pCtrl->UpdateWindow();
}
}