baseedit.cpp

来自「用VC+SQL实现的物流管理系统 “RxMediaPlayer” 文件夹中存放」· C++ 代码 · 共 84 行

CPP
84
字号
// BaseEdit.cpp : implementation file
//

#include "stdafx.h"
#include "MyProject.h"
#include "BaseEdit.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CBaseEdit

CBaseEdit::CBaseEdit()
{
	m_IsOnly=false;
	m_IsBool=false;
}

CBaseEdit::~CBaseEdit()
{
}


BEGIN_MESSAGE_MAP(CBaseEdit, CEdit)
	//{{AFX_MSG_MAP(CBaseEdit)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CBaseEdit message handlers

BOOL CBaseEdit::PreTranslateMessage(MSG* pMsg) 
{
	if(m_IsOnly==true && pMsg->message==WM_KEYDOWN)//只允许输入金额
	{
			//如果输入的字符不是1~9或“.”或其它功能键
		if((pMsg->wParam<0x30 || pMsg->wParam>0x39) && pMsg->wParam!=190 && pMsg->wParam!=8 && pMsg->wParam!=13)
			if(pMsg->wParam<VK_NUMPAD0 || pMsg->wParam>VK_NUMPAD9)// &&&&  pMsg->wParam!=VK_PERIOD
				pMsg->wParam=VK_CONTROL;
	}

	if(m_IsBool==true && pMsg->message==WM_KEYDOWN)
	{
		if(pMsg->wParam!=VK_NUMPAD0 && pMsg->wParam!=VK_NUMPAD1&&pMsg->wParam!=0x30 && pMsg->wParam!=0x31 && pMsg->wParam!=8 &&pMsg->wParam!=13)
				pMsg->wParam=VK_CONTROL;
	}
	if(pMsg->message==WM_KEYDOWN && pMsg->wParam==13)
		pMsg->wParam=9;

	if(pMsg->message==WM_KILLFOCUS)
	{
			CString sText;
	this->GetWindowText(sText);
	int Point=sText.Find(".");
	if(Point!=0)
	{
		int NextPoint=sText.Find(".",Point+1);
		if(NextPoint!=-1 && m_IsOnly==true)
		{
			MessageBox("请输入正确的数据!","系统提示",MB_OK|MB_ICONSTOP);
			this->SetFocus();
		}
	}
	}

	return CEdit::PreTranslateMessage(pMsg);
}

void CBaseEdit::IsMoneyOnly(bool bOnly)
{
	m_IsOnly=bOnly;
}


void CBaseEdit::IsBoolOnly(bool bOnly)
{
	m_IsBool=bOnly;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?