Chapter 17: Track-Based Controls Visual C++ and MFC Fundamentals
udAccel.nInc = 5;
m_Spin.SetAccel(SizeOfAccel, &udAccel);
m_Spin.SetRange(12, 168);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
If a spin button has been created already, to find its incremental value, you can call the
CSpinButtonCtrl::GetAccel() method. Its syntax is:
UINT GetAccel(int nAccel, UDACCEL* pAccel) const;
Normally, the values of a spin button are decimal integers. Alternatively, if you prefer the
values to be given in hexadecimal format, set the range accordingly and call the
CSpinButtonCtrl::SetBase() method. Its syntax is:
int SetBase (int nBase);
Using this method, if you want the value to be decimal, pass the nBase argument as 10. If
you want hexadecimal values, pass the argument as 16. Here is an example:
BOOL CSpinDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
CSpinButtonCtrl *SpinCtrl = new CSpinButtonCtrl;
CStatic *SpinBuddy;
SpinCtrl->Create(WS_CHILD | WS_VISIBLE | UDS_SETBUDDYINT,
CRect(60, 10, 80, 35), this, 0x128);
SpinCtrl->SetRange(0x04, 0xFF06);
SpinCtrl->SetBase(16);
SpinBuddy = reinterpret_cast<CStatic *>(GetDlgItem(IDC_SPIN_BUDDY));
SpinCtrl->SetBuddy(SpinBuddy);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
To find out the current base, decimal or hexadecimal, that a spin button is using for its
values, call the CSpinButtonCtrl::GetBase() method. Its syntax:
UINT GetBase() const;