Visual C++ and MFC Fundamentals Chapter 18: Progress-Based Controls
SetTimer(IDT_RLUNG, 850, NULL);
SetTimer(IDT_PANCREAS, 800, NULL);
SetTimer(IDT_LIVER, 1200, NULL);
SetTimer(IDT_BLADDER, 550, NULL);
SetTimer(IDT_STOMACH, 1500, NULL);
srand(static_cast<unsigned>(time(NULL)));
return TRUE; // return TRUE unless you set the focus to a control
}
- Save All
18.3.3..Progress Bars Methods and Events..................................................
The values of a progress bar are float, unlike the progress control that mostly uses
integers. To set the minimum value for the progress bar, call its SetMin() method. To set
the maximum value, call the SetMax() method. These two methods expects a float
number as argument. If these values have already been set, you can retrieve them by
calling the GetMin() or the GetMax() methods respectively.
To set the initial value of the progress bar or to change its value any timer, you can call
the SetValue() method. Also, at anytime, you can retrieve the position of the control by
calling the GetValue() method.
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 you 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.
Practical Learning: Using a ProgressBar Control
- Generate a WM_TIMER message for the dialog box and implement it as follows:
void CBodyMonitorDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
float Blood = static_cast<float>(rand() % 100);
float Heart = static_cast<float>(rand() % 100);
float Kidney = static_cast<float>(rand() % 100);
float Brain = static_cast<float>(rand() % 100);
float LeftLung = static_cast<float>(rand() % 100);
float RightLung = static_cast<float>(rand() % 100);
float Pancreas = static_cast<float>(rand() % 100);
float Liver = static_cast<float>(rand() % 100);
float Bladder = static_cast<float>(rand() % 100);
float Stomach = static_cast<float>(rand() % 100);
if( nIDEvent == IDT_BLOOD )
{
m_Blood.put_Value(Blood);
// Make a sound if the value of the heart is too high
if( Blood >= 85 )