You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

90 lines
1.4 KiB
C++

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

// EditInput.cpp : 实现文件
//
#include "stdafx.h"
#include "CH91PayloadSoftware.h"
#include "EditInput.h"
// CEditInput
IMPLEMENT_DYNAMIC(CEditInput, CEdit)
CEditInput::CEditInput()
{
}
CEditInput::~CEditInput()
{
}
BEGIN_MESSAGE_MAP(CEditInput, CEdit)
ON_WM_CHAR()
END_MESSAGE_MAP()
void CEditInput::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// 保证小数点最多只能出现一次
if (nChar == '.')
{
CString str;
// 获取原来编辑框中的字符串
GetWindowText(str);
if (str.Find('.') != -1)
{
//字符串中已经有小数点,不输入
}
else
{
CEdit::OnChar(nChar, nRepCnt, nFlags);
}
}
//负号只能出现一次,并且只能在第一个字符出现
else if (nChar == '-')
{
CString str;
GetWindowText(str);
if (str.IsEmpty() )
{
CEdit::OnChar(nChar, nRepCnt, nFlags);
}
else
{
int nSource, nDestination;
//当前选中编辑框中的内容
GetSel(nSource, nDestination);
//当光标位于第一个位置时
if (nSource == 0)
{
//nDestination = nSource时表示未选中
//光标位于最前方并且str中已经有'-'不操作
if (str[0] == '-' && nDestination == 0)
{
}
else
CEdit::OnChar(nChar, nRepCnt, nFlags);
}
else
{
}
}
}
//小数点负号还应该允许输入数字backspace, delete
else if( (nChar>='0' && nChar<='9') || (nChar == 0x08) || (nChar == 0x10) )
{
CEdit::OnChar(nChar, nRepCnt, nFlags);
}
//其余不响应
else
{
}
//CEdit::OnChar(nChar, nRepCnt, nFlags);
}