Chapter 17: Track-Based Controls Visual C++ and MFC Fundamentals
//{{AFX_DATA_INIT(CCDPublisherDlg)
m_EditQuantity = _T(" 1 ");
m_UnitPrice = _T("$20.00");
m_TotalPrice = _T("$20.00");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
- Save All
17.2.2..Using an UpDown Control................................................................
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:
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);