Files
envi-code/SourceCode/Code2026/tg_shs/shs_kerncmd/NumEdit.cpp
T
gjm 164968b62e chore
把非utf8-bom编码的cpp/h文件改为 utf8 bom 编码, msvc识别utf8编码时,如果不是bom格式的,会使用当前cp_oem来解码.
2026-10-04 00:04:20 +08:00

103 lines
2.0 KiB
C++

// NumEdit.cpp : implementation file
#include "stdafx.h"
#include "NumEdit.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CNumEdit
CNumEdit::CNumEdit()
{
}
CNumEdit::~CNumEdit()
{
}
BEGIN_MESSAGE_MAP(CNumEdit, CEdit)
//{{AFX_MSG_MAP(CNumEdit)
ON_WM_CHAR()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CNumEdit message handlers
void CNumEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
CString text;
if (nChar == 8)
CEdit::OnChar(nChar, nRepCnt, nFlags);
if (nChar == 3)
CEdit::Copy();
if (nChar == 24)
CEdit::Cut();
if (nChar == 26)
CEdit::Undo();
if (nChar == 22)
CEdit::Paste();
POINT caret;
::GetCaretPos (&caret);
caret.x = LOWORD (CharFromPos (caret));
GetWindowText (text);
if (isdigit(nChar))
CEdit::OnChar(nChar, nRepCnt, nFlags);
else if (nChar == '-') {
if (!caret.x){
if (((text.GetLength() > 0) && (text[0]!='-')) || (text.GetLength()==0))
CEdit::OnChar(nChar, nRepCnt, nFlags);
} else {
TCHAR cc=text.GetAt(caret.x-1);
if (( cc == 'e') || (cc == 'E'))
CEdit::OnChar(nChar, nRepCnt, nFlags);
}
} else if ((nChar == 'e') || (nChar == 'E')){
if ((caret.x == 1) && (text[0] == '-'))
return ;
if (caret.x){
for (int i=0; i<text.GetLength(); i++) {
TCHAR cc=text[i];
if ((cc == 'e') ||(cc == 'E'))
return ;
}
CEdit::OnChar(nChar, nRepCnt, nFlags);
}
}else if (nChar == '.') {
for (int i=0; i<text.GetLength(); i++) {
TCHAR cc=text[i];
if (cc == '.')
return ;
}
for (i=0; i<text.GetLength(); i++) {
TCHAR cc = text[i];
if (((cc == 'e') ||(cc=='E')) && (caret.x > i))
return ;
}
CEdit::OnChar(nChar, nRepCnt, nFlags);
}
}
void CNumEdit::SetValue(double val)
{
CString tmp;
tmp.Format (_T("%G"),val);
SetWindowText(tmp);
}
double CNumEdit::GetValue()
{
CString tmp;
GetWindowText(tmp);
return _tcstod(tmp,NULL);
}