CD Publisher |
|
Overview |
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. Prerequisites: |
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:
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. void CDlgSpin::OnConfigureUpDown() { // TODO: Add your control notification handler code here m_UpDown.SetMin(12); m_UpDown.SetMax(250); } 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: void CDlgSpin:: OnConfigureUpDown() { // TODO: Add your control notification handler code here m_UpDown.SetMin(12); m_UpDown.SetMax(250); m_UpDown.SetValue(88); } To get the value of an UpDown control, call its GetValue() method. When using the UpDown control by clicking one of its buttons buttons, its value increases or decreases by one. If you want a different incremental value, specify it using the Increment edit box.
To programmatically set an incremental value, call the SetIncrement() method. Here is an example: void CDlgSpin:: OnConfigureUpDown() { // TODO: Add your control notification handler code here m_UpDown.SetMin(12); m_UpDown.SetMax(250); m_UpDown.SetValue(88); m_UpDown.SetIncrement(5); }
|
|
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. |
|
|
Copyright © 2003-2015, FunctionX, Inc. |
|