00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "stdafx.h"
00023 #include "floatedit.h"
00024
00025
00026
00027 IMPLEMENT_DYNAMIC(CFloatEdit, CEdit)
00028
00029 bool CFloatEdit::GetFloat(float& f)
00030 {
00031 CString s;
00032 GetWindowText(s);
00033 return(_stscanf(s, _T("%f"), &f) == 1);
00034 }
00035
00036 double CFloatEdit::operator = (double d)
00037 {
00038 CString s;
00039 s.Format(_T("%.4f"), d);
00040 SetWindowText(s);
00041 return(d);
00042 }
00043
00044 CFloatEdit::operator double()
00045 {
00046 CString s;
00047 GetWindowText(s);
00048 float f;
00049 return(_stscanf(s, _T("%f"), &f) == 1 ? f : 0);
00050 }
00051
00052 BEGIN_MESSAGE_MAP(CFloatEdit, CEdit)
00053 ON_WM_CHAR()
00054 END_MESSAGE_MAP()
00055
00056 void CFloatEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
00057 {
00058 if(!(nChar >= '0' && nChar <= '9' || nChar == '.' || nChar == '\b'))
00059 return;
00060
00061 CString str;
00062 GetWindowText(str);
00063
00064 if(nChar == '.' && (str.Find('.') >= 0 || str.IsEmpty()))
00065 return;
00066
00067 int nStartChar, nEndChar;
00068 GetSel(nStartChar, nEndChar);
00069
00070 if(nChar == '\b' && nStartChar <= 0)
00071 return;
00072
00073 CEdit::OnChar(nChar, nRepCnt, nFlags);
00074 }
00075
00076
00077
00078 IMPLEMENT_DYNAMIC(CIntEdit, CEdit)
00079
00080 BEGIN_MESSAGE_MAP(CIntEdit, CEdit)
00081 ON_WM_CHAR()
00082 END_MESSAGE_MAP()
00083
00084 void CIntEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
00085 {
00086 if(!(nChar >= '0' && nChar <= '9' || nChar == '-' || nChar == '\b'))
00087 return;
00088
00089 CString str;
00090 GetWindowText(str);
00091
00092 if(nChar == '-' && !str.IsEmpty() && str[0] == '-')
00093 return;
00094
00095 int nStartChar, nEndChar;
00096 GetSel(nStartChar, nEndChar);
00097
00098 if(nChar == '\b' && nStartChar <= 0)
00099 return;
00100
00101 if(nChar == '-' && (nStartChar != 0 || nEndChar != 0))
00102 return;
00103
00104 CEdit::OnChar(nChar, nRepCnt, nFlags);
00105 }
00106
00107
00108
00109 IMPLEMENT_DYNAMIC(CHexEdit, CEdit)
00110
00111 bool CHexEdit::GetDWORD(DWORD& dw)
00112 {
00113 CString s;
00114 GetWindowText(s);
00115 return(_stscanf(s, _T("%x"), &dw) == 1);
00116 }
00117
00118 DWORD CHexEdit::operator = (DWORD dw)
00119 {
00120 CString s;
00121 s.Format(_T("%08x"), dw);
00122 SetWindowText(s);
00123 return(dw);
00124 }
00125
00126 CHexEdit::operator DWORD()
00127 {
00128 CString s;
00129 GetWindowText(s);
00130 DWORD dw;
00131 return(_stscanf(s, _T("%x"), &dw) == 1 ? dw : 0);
00132 }
00133
00134 BEGIN_MESSAGE_MAP(CHexEdit, CEdit)
00135 ON_WM_CHAR()
00136 END_MESSAGE_MAP()
00137
00138 void CHexEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
00139 {
00140 if(!(nChar >= 'A' && nChar <= 'F' || nChar >= 'a' && nChar <= 'f'
00141 || nChar >= '0' && nChar <= '9' || nChar == '\b'))
00142 return;
00143
00144 CString str;
00145 GetWindowText(str);
00146
00147 int nStartChar, nEndChar;
00148 GetSel(nStartChar, nEndChar);
00149
00150 if(nChar == '\b' && nStartChar <= 0)
00151 return;
00152
00153 if(nChar != '\b' && nEndChar - nStartChar == 0 && str.GetLength() >= 8)
00154 return;
00155
00156 CEdit::OnChar(nChar, nRepCnt, nFlags);
00157 }