Chapter 18: Progress-Based Controls Visual C++ and MFC Fundamentals
If the range of values has already been set and you want to find it out, you can call the
CProgressCtrl::GetRange() method. Its syntax is:
void GetRange(int& nLower, int& nUpper);
This member function returns two values: nLower is the current minimum value of the
control while nUpper is returned as its maximum value.
Once a progress control has been created and when it comes up, it assumes its minimum
value. While the control is working, it keeps changing its value by stepping to the next
value. By default, its next value is set to 10. If you want to specify a different incremental
value, call the CProgressCtrl::SetStep() method whose syntax is:
int SetStep(int nStep);
The nStep argument is the value set to increment the position of the progress control.
Once this value is set, when the control is progressing, it increments its value by that
value to get to the next step. If you want to explicitly ask it to step to the next incremental
value, call the CProgressCtrl::StepIt() method. Its syntax is:
int StepIt( );
Although the user cannot directly modify it, you can change the value of a progress bar
by calling the CProgressCtrl::SetPos() method whose syntax is:
int SetPos(int nPos);
This method can be called either to set the initial value of the control or to simply change
it at any time. Here is an example:
BOOL CDlgProgress1Dlg::OnInitDialog()
{
CDialog::OnInitDialog();
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
CProgressCtrl *Progress = new CProgressCtrl;
Progress->Create(WS_CHILD | WS_VISIBLE, CRect(10, 10, 288, 35), this,0x16);
Progress->SetRange(1, 100);
Progress->SetPos(38);
return TRUE; // return TRUE unless you set the focus to a control
}
While the control is working, if you want to find out the value it is holding, you can call
the CProgressCtrl::GetPos() method. Its syntax is:
int GetPos( );
This method returns the current position of the progress control.