Besides the spin
button, Visual C++ ships with an ActiveX control that provides the same functionality. To use this object, you can
right-click the form or dialog box and click Insert ActiveX Control. Then, on the Insert ActiveX Control dialog box,
click Microsoft UpDown Control. If there are two versions provided, you should select the latest, which usually has a higher version number.

The Microsoft UpDown control is simply a spin button but with true visual accessibility and rapid application development (RAD) concept. Like the spin button, it is equipped with two buttons. Each button has a small picture (a bitmap) that displays an arrow.

The application we are about to develop is for a CD publishing small business. This company
manufactures compact discs for self-promoting musicians and small business that want to sell their own CDs. When taking an order of a new CD, the company charges:

$20/CD if the customer is ordering less than 20 units

$15/CD if the customer is ordering up to 50 units

$12/CD if the customer is ordering up to 100 units

$8/CD if the customer is ordering up to 500 units

$5/CD for any order over 500 units

You can start by creating a new Dialog-based application named
CDPublisher

Set its title to Compact Disc Publisher

You can also delete the TODO line and the OK button

Change the Caption of the Cancel button to Close.
Add a Picture control to the dialog
box

Set its Color property to Etched and check its
Modal Frame check box or set it to True.

Without adding the updown control, design the dialog box as
on the above picture. The names of the edit boxes from left to right are IDC_EDIT_QTY, IDC_UNITPRICE, and IDC_TOTALPRICE

Add a CString variable for the IDC_EDIT_QTY control and name it m_EditQuantity

Add a CString variable for the IDC_ UNITPRICE control and name it m_UnitPrice

Add a CString variable for the IDC_ TOTALPRICE control and name it m_TotalPrice

Access the source code of the CCDPublisherDlg class and, in its constructor, initialize the edit boxes to 1 or $20.00

To provide an UpDown control to your application, display the Insert ActiveX Control
dialog box, select Microsoft UpDown Control 6.0 and click OK. If you plan to refer to the control in your code, you can add a variable for it. When you do this, Visual C++ would create and even implement its class, giving all of its code (its header and source files). You can then find out that the
UpDown control is based on the CUpDown class which itself is based on CWnd, making it
convenient to use CWnd properties and methods.

Like the spin button, the UpDown control cannot display its value to the user. If you want an accompanying control to play that role, you should place the new
UpDown control next to a text-based control such as an edit box. You have the option of positioning the
UpDown control to the left or the right side of its buddy control.

After placing the UpDown control on the parent window, by default, its arrow buttons point up and down. If you want the arrows to point left and right, change the value of the Orientation property.

To make the UpDown control easier to configure, you can set its range value visually. The minimum value is set using the Min edit box the maximum value is set on the Max edit box. To programmatically change the minimum value, call the
SetMin() method. In the same way, the maximum value can be changed by calling the
SetMax() method. Here is an example:

To get the minimum value of an UpDown control, call the
GetMin() method. To get the maximum value of an UpDown control, call the
GetMax() method.

After setting the minimum and the maximum values, you can specify the initial value the
UpDown control would hold when the application comes up. This value is set using the Value edit box and it must be in the range (Min, Max). To change the value with code, call the
SetValue() method and pass it the desired but valid value. Here is an example:

To know what increment value an UpDown control is using, call its GetIncrement() method.

Right-click in the middle of the dialog box and click Insert ActiveX Control
and click OK

Position the new control to the right side of the Number of CDs edit box and resize it:

Using the Properties window, change its ID to IDC_QUANTITY

Set the values of the Min edit box 1 and the Max edit box to 5000

Add a variable to the UpDown control. You may receive a message box informing you that the control needs to be inserted into your
project. Click OK. Click OK again

Set the name of the variable to m_Quantity

Click OK twice

In Class View, expand CUpDown and double-click it to display its source code

The UpDown Control Events

The UpDown control makes an object distinction between its button components. For example, when the user clicks the up pointing arrow button, the control fires the
UpClick() event. On the other hand, when the user clicks the down pointing arrow button, the control sends a
DownClick() event. These allow you to treat each event separately if you want.

If you are more interested in the value of the UpDown control, when the users clicks either of its button, the value of the control changes. Once the value of the control has been modified, it fires a Change() event.

The UpDown control provides bonus events related to the mouse. When the mouse arrives to passes over this control, the
MouseMove() event is fired. If the user presses a mouse button on the control. It fires the
MouseDown() event. When the user releases the mouse button, the MouseUp() event is fired.

If you are using MSVC 6, display the ClassWizard and the Message Maps property page. Click the IDC_QUANTITY. In the Messages section, double-click Change, click OK and click Edit Code
If you are using MSVC 7, display the dialog box and click the UpDown control. On the Property window, click the Control Events button . Click the arrow of the Change combo box and select the only item in the list