A Progress control is something that an application can use to
indicate the progress of an ongoing operation. It consists of
a rectangle that is gradually filled, from left to right, with
the system highlight color as an operation progresses. This
control is can be manipulated by using the class CProgressCtrl.
This article is a brief about how to use this control with
reference to the class CProgressCtrl in an MFC application
with dialogs.
CProgressCtrl - Setting up the application:
The following steps explain how to setup a basic dialog
application to hold a progress bar control. If there is a
dialog to hold the Progress bar (of CProgressCtrl ) the
following steps can be ignored.
-
Create a new MFC AppWizard executable project as a dialog
based application.
- The
application can also be an SDI/MDI app, where in the dialog
can be inserted as a resource into the SDI/MDI projects.
- From
the controls toolbox, choose the progress bar control and
place it on a dialog box.
- Add a
class member for the CProgressCtrl for the progress
bar control. This sample assumes the variable name to be
m_Progress.
CProgressCtrl - Sample usage:
The progress control can be initialized and used wherever
needed. A dialog can have multiple operations/functionalities
to be supported. For each and every operation, the
CProgressCtrl can be initialized and used to indicate the
progress of the operation.
The following is the sample piece of code to show the progress
of a CProgressCtrl from 1 to 100 with increments of 2 at every
operation.
m_Progress.SetRange(0,100);
m_Progress.SetStep(2);
for(int i=0;i<50;i++)
{
m_Progress.StepIt();
}
or instead of the CProgressCtrl.SetStep() and
CProgressCtrl.StepIt() combination, a single function
CProgressCtrl.StePos can also be used.
The above piece of code can be applied anywhere the control
needs to be manipulated.
Also it is to be noted that the control need not be used only
by the resource editor. It can also be created dynamically by
using the CProgressCtrl.Create function.