Chapter 17: Track-Based Controls Visual C++ and MFC Fundamentals
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 user clicks either
of its buttons, 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.
Practical Learning: Configuring an UpDown Control
- 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
- Implement the event as follows:
void CCDPublisherDlg::OnChangeQuantity()
{
// TODO: Add your control notification handler code here
int Quantity;
double UnitPrice, TotalPrice;
Quantity = m_Quantity.GetValue();
if( Quantity < 20 )
UnitPrice = 20;
else if( Quantity < 50 )
UnitPrice = 15;
else if( Quantity < 100 )
UnitPrice = 12;
else if( Quantity < 500 )
UnitPrice = 8;
else
UnitPrice = 5;
TotalPrice = Quantity * UnitPrice;
m_EditQuantity.Format("%d", Quantity);
m_UnitPrice.Format("$%.2f", UnitPrice);
m_TotalPrice.Format("$%.2f", TotalPrice);
UpdateData(FALSE);
}
- Test the application