📄 crangeedit.cpp
字号:
#include "stdafx.h"
#include "CRangeEdit.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
// Defines
//
#define BLANK_ENTRY -1
CRangeEdit::CRangeEdit() :
myMin ( 0 ), // Initialize member variables to zero
myMax ( 100 ),
myLastValidValue ( 0 )
{
}
CRangeEdit::~CRangeEdit()
{
}
BEGIN_MESSAGE_MAP(CRangeEdit, CEdit)
//{{AFX_MSG_MAP(CRangeEdit)
ON_CONTROL_REFLECT(EN_UPDATE, OnUpdate)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
void CRangeEdit::OnUpdate()
{
CString strWindowText;
LONG ValidationNumber;
strWindowText.Empty ( );
ValidationNumber = 0;
RemoveLeadingZeros ( );
GetWindowText ( strWindowText );
if ( strWindowText.IsEmpty ( ) )
{
myLastValidValue = BLANK_ENTRY;
}
else
{
ValidationNumber = atol ( strWindowText );
if ( ( ValidationNumber < myMin ) || ( ValidationNumber > myMax ) )
{
if ( myLastValidValue >= 0 )
{
strWindowText.Format ( "%d", myLastValidValue );
}
else
{
strWindowText.Empty ( );
}
SetWindowText ( strWindowText );
SetSel ( strWindowText.GetLength ( ), strWindowText.GetLength ( ) );
MessageBeep ( 0xFFFFFFFF );
}
else
{
myLastValidValue = ValidationNumber;
}
}
}
void CRangeEdit::SetRange ( LONG inLMin, LONG inLMax )
{
// Set the member variables
//
myMin = inLMin;
myMax = inLMax;
myLastValidValue = myMin;
}
void CRangeEdit::RemoveLeadingZeros ( void )
{
CString strWindowText;
SHORT index;
strWindowText.Empty ( );
index = 0;
GetWindowText ( strWindowText );
if ( strWindowText.GetLength ( ) > 1 )
{
index = strWindowText.FindOneOf ( "123456789" );
if ( index > 0 )
{
strWindowText = strWindowText.Mid ( index );
}
else if ( index == -1 )
{
strWindowText = "0";
}
if ( index != 0 )
{
SetWindowText ( strWindowText );
SetSel ( 0, 0 );
}
}
}
#undef BLANK_ENTRY
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -