[MFC] FloatEdit
pragma once
// ListBox
class FloatEdit : public CEdit
{
DECLARE_DYNAMIC(FloatEdit)
public:
FloatEdit();
virtual ~FloatEdit();
protected:
DECLARE_MESSAGE_MAP()
public:
virtual BOOL PreTranslateMessage(MSG* pMsg);
};
// ListBox.cpp: 实现文件
//
include "pch.h"
include "util/FloatEdit.h"
// ListBox
IMPLEMENT_DYNAMIC(FloatEdit, CEdit)
FloatEdit::FloatEdit()
{
}
FloatEdit::~FloatEdit()
{
}
BEGIN_MESSAGE_MAP(FloatEdit, CEdit)
END_MESSAGE_MAP()
// ListBox 消息处理程序
BOOL FloatEdit::PreTranslateMessage(MSG* pMsg)
{
// TODO: 在此添加专用代码和/或调用基类
if (pMsg->message == WM_KEYDOWN)
{
bool isHavePoint = false;
wchar_t str[32];
GetWindowTextW(str, 32);
int length = wcslen(str);
for (int i = 0; i < length; ++i)
{
if (str[i] == 46)
{
isHavePoint = true;
}
}
if ((pMsg->wParam == 110) || (pMsg->wParam == 190)) // 小数点
{
if (isHavePoint)
return TRUE;
}
else if ((pMsg->wParam == 8) || (pMsg->wParam == 46)) // 退格和删除
{
return FALSE;
}
else if ((pMsg->wParam >= 48) || (pMsg->wParam <= 57)) // 字符0 至 字符9
{
return FALSE;
}
else if ((pMsg->wParam >= 96) || (pMsg->wParam <= 105)) // 字符0 至 字符9
{
return FALSE;
}
}
return CEdit::PreTranslateMessage(pMsg);
}

浙公网安备 33010602011771号