SPIN CONTROL |
|
A spin button is a control equipped with two buttons and each button displays an arrow. The spin button allows the user to navigate through a range of value using the arrow buttons to increase or decrease the value held by the control. |
To create a spin button, you can use the Spin button from the Controls toolbox. Alternatively, Visual C++ provides the Microsoft UpDown Control as an ActiveX control.
// TODO: Add extra initialization here m_Spin.SetRange(0, 54); c) After you build and execute your app now, do you like it, now that the upper arrow gives positive values? d) To make it a little interesting, let's see how you can make the Edit dislay a certain value at startup. Press Ctrl+W to access the ClassWizard. Click the Member Variables tab. In the Class name combo box, choose CExoSpinDlg and double-click IDC_EDITSPIN. Add the member variable m_EditSpin of type CString and press Enter. Then, click OK in the ClassWizard. Our current spin range is from 0 to 54. In the OnInitDialog() function, change it to be 5 to 86. // TODO: Add extra initialization here m_Spin.SetRange(5, 86); Let's configure the Edit box to display a certain value at startup, namely 12. In the CExoSpinDlg constructor, ClassWizard initialized the m_EditSpin variable you created as empty. Modify that initialization to look like this: //{{AFX_DATA_INIT(CExoSpinDlg) m_EditSpin = _T("12"); //}}AFX_DATA_INIT e) Those are the minimum requirements you need to specify when you are creating a CSpinCtrl object. 4. Now, you can control the incremental values of the spin button by using the CSpinButtonCtrl::SetAccel() function. The SetAccel() function takes/uses two arguments. The first is an integer that uses the clock to specify the number of seconds that will elapse before performing the incrementing (if I were you, I would not bother understanding, just look ahead at how the function is implemented). The second argument is a structure that controls the incrementing value in seconds at clock speed. This structure, called UDACCEL, needs two values, the first is a clock time in seconds that specifies the rate value (?!?) of acceleration. The second argument, which is our interest, is actually the real incrementing value of the spin button. To implement it, or to see how it is done, we
will declare a UDACCEL structure, call it AccellValue; then we will set
its clock speed to 1000 and the spin button incrementing value to 5 (our
example uses 5, you can use any (reasonable, of course) value you want);
and finally call the CSpinButtonCtrl::SetAccel() function with our defined
arguments. |
// TODO: Add extra initialization here UDACCEL AccellValue; AccellValue.nSec = 1000; AccellValue.nInc = 5; m_Spin.SetRange(6, 82); m_Spin.SetAccel(1, &AccellValue); //m_Spin.SetRange(6, 82); //m_Spin.SetAccel(1, &AccellValue); |
This section was modified and improved with help from |
|
Copyright © 2003-2015, FunctionX |
|