Chapter 17: Track-Based Controls Visual C++ and MFC Fundamentals
17.1.3..The Spin Button Properties................................................................
By default, a spin button appears with an up and a down pointing arrows. If you want the
arrows to be horizontally directed, change the value of the Orientation property from
Vertical (the default) to Horizontal. If you are programmatically creating the control, add
the UDS_HORZ style to it. Here is an example:
SpinCtrl->Create(WS_CHILD | WS_VISIBLE | UDS_HORZ,
CRect(60, 10, 80, 35), this, 0x128);
We mentioned already that the value of the spin changes as the user clicks or holds the
mouse on one arrow of the control. In the same way, if you want the user to be able to
increment or decrement the value of the control using the up and down arrow keys of the
keyboard, set the Arrow Keys property to True at design time or add the
UDS_ARROWKEYS style.
As stated already, a spin button cannot display its value to the user. If you want to inform
the user about the value of the control as it is being incremented or decremented, you can
add another, usually text-based, control, such as an edit box. This control is called the
buddy window of the spin button. The control should be positioned on one horizontal
side of the spin button. After adding that new control, you should let the spin button
know on what side the accompanying control is positioned, left or right. To do this, select
the appropriate value in the Alignment property.
If you are programmatically creating the control, to position the spin button to the left
edge of the buddy window, add the UDS_ALIGNLEFT style. On the other hand, if you
want the spin button on the right side of the buddy window, apply the
UDS_ALIGNRIGHT style instead. Just like at design time you cannot apply both styles,
at run time, do not add both the UDS_ALIGNLEFT and the UDS_ALIGNRIGHT
styles.
If you want the spin button to use an already existing and previously added control as its
buddy window, set the Auto Buddy property to True or apply the UDS_AUTOBUDDY
style. In this case, the control that was just previously added to the host, before adding the
spin button, would be used as its buddy.
After specifying what control would be the buddy window of the spin button, when the
user clicks the arrows of the button, the buddy would display its current value. If you
want to make sure that the buddy window display only integral values, whether decimal
or hexadecimal, change the Set Buddy Integer property to True. If you are
programmatically creating the control, you can add the UDS_SETBUDDYINT style:
SpinCtrl->Create(WS_CHILD | WS_VISIBLE | UDS_SETBUDDYNT,
CRect(60, 10, 80, 35), this, 0x128);
When the buddy window displays the values of the spin button and when the value gets
over 999, if you want the number to be separated by a comma, set the No Thousands
property to True. To apply this property with code, add the UDS_NOTHOUSANDS
style. If you do not want the thousand sections to be separated by comma, set the No
Thousands property to False or omit the UDS_NOTHOUSANDS style.
Imagine you create a spin button and specify its range of values from 3 to 22 with an
incremental of 5. When the control is incremented to 20 and the user clicks the up arrow
button or presses the up arrow key, you can decide that the incrementing should stop at
20 or wrap to 22, although 22 is not a valid incremental value for this scenario. The