Visual C++ and MFC Fundamentals Chapter 18: Progress-Based Controls
- Add a Control Variable for the progress controls and name them from top down as:
m_ProgressHours, m_ProgressMinutes, and m_ProgressSeconds respectively - Add a CString Value Variable for the IDC_VAL_HOURS, the
IDC_VAL_MINUTES, and the IDC_VAL_SECONDS identifiers and name them
m_ValueHours, m_ValueMinutes, and m_ValueSeconds respectively - Test the application and return to MSVC
18.2.3..Progress Control Methods and Events.............................................
We mentioned already, an MFC progress bar is based on the CProgressCtrl class.
Therefore, to dynamically create a progress bar, you can declare a variable or a pointer to
CProgressCtrl using its constructor. To initialize it, call its Create() method and set the
necessary characteristics. 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);
return TRUE; // return TRUE unless you set the focus to a control
}
To express its evolution, a progress bar uses values from a minimum to a maximum.
These limit values are set using the CProgressCtrl::SetRange() or the
CProgressCtrl::SetRange32() methods. Their syntaxes are:
void SetRange(short nLower, short nUpper);
void SetRange32(int nLower, int nUpper);
The nLower argument sets the minimum value for the control. The nUpper argument is
the maximum value of the control. 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);
return TRUE; // return TRUE unless you set the focus to a control
}