Jump to content

Using CProgressCtrl in MFC Dialog Box

- - - - -

  • Please log in to reply
No replies to this topic

#1
mnirahd

mnirahd

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 330 posts
Introduction

In lengthy operation, like file upload/download operation, we often like to show users about the progress of operation. In MFC application, we can use CProgressCtrl to show progress of an operation. It is a rectangle that is gradually filled with the system highlight color as the operation progresses.

More about CProgressCtrl

The progress control is represented in MFC by class CProgressCtrl. When you initially create the progress control, you specify its size and position, parent window (usually a dialog box), and ID. By using the dwStyle parameter, you can also specify various window styles for the control and styles for how it fills.

For how we can set a style for progress bar, see

Styles for the Progress Control (MFC)

For general setting for progress bar, see

Settings for the Progress Control (MFC)

For manipulating progress bar, see

Manipulating the Progress Control (MFC)

Example: How to use CProgressCtrl in MFC Dialog Application

CProgressCtrl
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.


1. 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.

2. 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.

References:

1. Using CProgressCtrl (MFC)
2. MFC CProgressCtrl




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users