Characteristics of a Progress Bar
|
|
The Orientation of a Progress Bar
|
|
After adding a progress bar to a parent window, it
assumes a horizontal position. This is controlled by the Orientation
property (not available in Version 5.0) whose default value is 0 -
ccOrientationHorizontal. If you want the progress bar to be
vertical, change this property to a 1 - ccOrientationVertical
value.
The Minimum and Maximum Values of a Progress Bar
|
|
The range of values that a progress bar can assume is
set using the Min property for the minimum value and the
Max field for the highest value. This can be done in the
Properties window.
The values of a progress bar are float,
unlike the progress control that mostly uses integers. To
programmatically set the minimum value for the progress bar, call its
put_Min() member function:
void put_Min(float newValue);
To set the maximum value, call the put_Max()
member function:
void put_Max(float newValue);
These two member functions expect a float number as
argument. If these values have already been set, you can retrieve them by
calling the get_Min() or the get_Max() member
functions respectively.
Practical
Learning: Setting the Minimum and Maximum Values
|
|
- Change the OnInitDialog event as follows:
BOOL CPledgeDistributionDlg::OnInitDialog()
{
CDialogEx::OnInitDialog();
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
m_SpinRate1.SetRange(0, 100);
m_SpinRate1.SetPos(50);
m_SpinRate2.SetRange(0, 100);
m_SpinRate2.SetPos(25);
m_SpinRate3.SetRange(0, 100);
m_SpinRate3.SetPos(25);
m_Proportion1.put_Min(0);
m_Proportion1.put_Max(100);
m_Proportion2.put_Min(0);
m_Proportion2.put_Max(100);
m_Proportion3.put_Min(0);
m_Proportion3.put_Max(100);
return TRUE; // return TRUE unless you set the focus to a control
}
The Value of a Progress Bar
|
|
To set the initial value of the progress bar or to
change its value any time, you can call the put_Value()
member function. Also, at anytime, you can retrieve the position of the
control by calling the get_Value() member function.
Practical
Learning: Setting the Value of a Progress Bar
|
|
- On the main menu, click Project -> Class Wizard...
- In the MFC Class Wizard, in the Class Name, select
CPledgeDistributionDlg, and click Commands.
In the list of Commands,
click IDC_SPIN_RATE1
- In the Messages list, click UDN_DELTAPOS
- Click Add Handler...
- Set the name to OnProportion1
- Click OK
- In the Commands list, click IDC_SPIN_RATE2
- In the Messages list, double-click UDN_DELTAPOS
- Set the name to OnProportion2
- Click OK
- In the Commands list, click IDC_SPIN_RATE3
- In the Messages list, double-click UDN_DELTAPOS
- Set the name to OnProportion3
- Click OK
- Click Edit Code
- Implement the events as follows:
void CPledgeDistributionDlg::OnProportion1(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMUPDOWN pNMUpDown = reinterpret_cast<LPNMUPDOWN>(pNMHDR);
// TODO: Add your control notification handler code here
UpdateData();
double Rest;
int Value1, Value2, Value3;
int Rate1, Rate2, Rate3;
// Get the current value of each spin control
Value1 = m_SpinRate1.GetPos();
Value2 = m_SpinRate2.GetPos();
Value3 = m_SpinRate3.GetPos();
// Calculate the percentage of each value based on the amount pledged
m_Amount1 = m_AmountPledged * Value1 / 100;
m_Proportion1.put_Value(m_SpinRate1.GetPos());
m_Amount2 = m_AmountPledged * Value2 / 100;
m_Proportion2.put_Value(m_SpinRate2.GetPos());
m_Amount3 = m_AmountPledged * Value3 / 100;
m_Proportion3.put_Value(m_SpinRate3.GetPos());
// Calculate the amount left
Rest = m_AmountPledged - m_Amount1 - m_Amount2 - m_Amount3;
// If the whole amount has not yet been distributed, display a message
if( Rest > 0 )
m_Message.Format(_T("$%.2f still to be used"), Rest);
else // If the whole amount has been distributed, don't display a message
m_Message = _T("");
UpdateData(FALSE);
*pResult = 0;
}
void CPledgeDistributionDlg::OnProportion2(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMUPDOWN pNMUpDown = reinterpret_cast<LPNMUPDOWN>(pNMHDR);
// TODO: Add your control notification handler code here
OnProportion1(pNMHDR, pResult);
*pResult = 0;
}
void CPledgeDistributionDlg::OnProportion3(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMUPDOWN pNMUpDown = reinterpret_cast<LPNMUPDOWN>(pNMHDR);
// TODO: Add your control notification handler code here
OnProportion1(pNMHDR, pResult);
*pResult = 0;
}
- To test the application, press F5
- Close it and return to your programming environment
Because the user cannot change the value of a progress
bar, it does not fire value-related events. On the other hand, it provides
you with the ability to do something when the user clicks or positions the
mouse over the control. If your user simply positions the mouse or moves it
on top of the progress bar, it fires the MouseMove event.
At the same time, if the user presses a mouse button on the progress bar, it
fires the MouseDown event. When the user releases the
mouse, the MouseUp event is sent. Clicking the progress bar
causes it to fire the Click event.
|
|