128 lines
2.4 KiB
C++
128 lines
2.4 KiB
C++
// XsSpinButtonCtrl.cpp : implementation file
|
|
//
|
|
|
|
#include "stdafx.h"
|
|
|
|
#include "XsSpinButtonCtrl.h"
|
|
|
|
#ifdef _DEBUG
|
|
#define new DEBUG_NEW
|
|
#undef THIS_FILE
|
|
static char THIS_FILE[] = __FILE__;
|
|
#endif
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// CXsSpinButtonCtrl
|
|
|
|
CXsSpinButtonCtrl::CXsSpinButtonCtrl()
|
|
{
|
|
}
|
|
|
|
CXsSpinButtonCtrl::~CXsSpinButtonCtrl()
|
|
{
|
|
}
|
|
|
|
|
|
BEGIN_MESSAGE_MAP(CXsSpinButtonCtrl, CSpinButtonCtrl)
|
|
//{{AFX_MSG_MAP(CXsSpinButtonCtrl)
|
|
ON_WM_LBUTTONDOWN()
|
|
//}}AFX_MSG_MAP
|
|
END_MESSAGE_MAP()
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// CXsSpinButtonCtrl message handlers
|
|
|
|
void CXsSpinButtonCtrl::OnLButtonDown(UINT nFlags, CPoint point)
|
|
{
|
|
// TODO: Add your message handler code here and/or call default
|
|
int nMin,nMax;
|
|
CXsSpinButtonCtrl::GetRange(nMin,nMax);
|
|
CString strNum;
|
|
CXsSpinButtonCtrl::GetBuddy()->GetWindowText(strNum);
|
|
CRect Rect;
|
|
CXsSpinButtonCtrl::GetWindowRect(Rect);
|
|
int nRight;
|
|
int nLeft;
|
|
if( strNum.Find('.') > 0 )
|
|
{
|
|
int nDotpos = strNum.Find('.');
|
|
CString strLeft = strNum.Left(nDotpos);
|
|
CString strRight = strNum.Right(nDotpos);
|
|
nRight = _ttoi(LPCTSTR(strRight));
|
|
nLeft = _ttoi(LPCTSTR(strLeft));
|
|
if(point.y <((Rect.bottom-Rect.top)/2))
|
|
{
|
|
nRight++;
|
|
}
|
|
else
|
|
{
|
|
nRight--;
|
|
}
|
|
if (nRight >= 10)
|
|
{
|
|
nLeft++;
|
|
CXsSpinButtonCtrl::SetPos(nLeft);
|
|
TCHAR a[3];
|
|
if (nLeft <= 4)
|
|
{
|
|
_itot(nLeft,a,10);
|
|
strNum = a;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
TCHAR a[3],b[3];
|
|
_itot(nLeft,a,10);
|
|
CXsSpinButtonCtrl::SetPos(nLeft);
|
|
if (nRight > 0)
|
|
{
|
|
strNum.Empty();
|
|
_itot(nRight,b,10);
|
|
strNum = strNum + a + _T('.') + b;
|
|
}
|
|
else if (nLeft != 0)
|
|
{
|
|
strNum.Empty();
|
|
strNum = strNum + a;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
int num = _ttoi(LPCTSTR(strNum));
|
|
TCHAR a[3],b[3];
|
|
if(point.y <((Rect.bottom-Rect.top)/2))
|
|
{
|
|
if (num < 4)
|
|
{
|
|
nRight = 1;
|
|
}
|
|
else
|
|
{
|
|
CXsSpinButtonCtrl::GetBuddy()->SetWindowText(LPCTSTR(strNum));
|
|
return;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (num > 0)
|
|
{
|
|
nRight = 9;
|
|
num--;
|
|
}
|
|
else
|
|
{
|
|
CXsSpinButtonCtrl::GetBuddy()->SetWindowText(LPCTSTR(strNum));
|
|
return;
|
|
}
|
|
}
|
|
CXsSpinButtonCtrl::SetPos(num);
|
|
_itot(num,a,10);
|
|
_itot(nRight,b,10);
|
|
strNum.Empty();
|
|
strNum = strNum + a + _T('.') + b;
|
|
}
|
|
CXsSpinButtonCtrl::GetBuddy()->SetWindowText(LPCTSTR(strNum));
|
|
//CSpinButtonCtrl::OnLButtonDown(nFlags, point);
|
|
}
|