Click here to Skip to main content
13,346,843 members (24,476 online)
Click here to Skip to main content
Add your own
alternative version


67 bookmarked
Posted 30 Nov 2000

Time to Complete Progress Control

, 30 Nov 2000
Rate this:
Please Sign up or sign in to vote.
A progress control that tells the user how long an operation has left to complete.

Sample Image - screenshot.gif


Progress bars are great for giving feedback to the user during lengthy operations. However, sometimes a percentage completion is not enough, so I came up with this little class to display an estimation of the length of time remaining to complete the operation.

The class uses a simple linear time calculation to predict the estimated time remaining. For example, if the progress is at 10% complete and it has taken 5 seconds so far, then it predicts that it will take another 45 seconds to get to 100%

The prediction is repeated every time the control is drawn, therefore assuming that the progress percentage is accurate, then the prediction should be reasonably so too.

TProgressTimeToComplete is provided ready to go and can be used as a direct replacement for the MFC CProgressCtrl class. The start time is taken from when the class is instantiated, but can be reset if the control is instantiated long before the processing by calling the ResetStartTime() member function.

There is one virtual function that can be overloaded in order to customise the display. GetRemainingText is called to format the text string which is written over the top of the progress bar. There are two parameters given the percentage complete and the estimated time to complete - in seconds. The default implementation of the function looks like this:

CString TProgressTimeToComplete::GetRemainingText(double lfPercent, 
    double lfSecsRemaining)
    CString str;
    int     nSeconds = (int)fmod(lfSecsRemaining, 60.0);

    if (lfSecsRemaining < 60)
        if (nSeconds < 1)
            str = "Less than a second";
            str.Format("%d second%s remaining", nSeconds, 
                 nSeconds==1? "":"s");
        int nMinutes = (int)(lfSecsRemaining/60.0);
        str.Format("%d minute%s, %d second%s remaining", 
             nMinutes, nMinutes==1? "":"s",
             nSeconds, nSeconds==1? "":"s");

    return str;


  • Horizontal and vertical progress bars are supported
  • Smooth and Blocked progress bars are supported
  • Expandable for custom text formatting
  • Interchangeable with MFC's CProgressCtrl
  • It's free !


The progress control uses Keith Rule's memory DC class for smooth painting. Enjoy!


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Craig Henderson
Technical Lead
United Kingdom United Kingdom
Craig graduated with a B.SC. Honours in Computing for Real Time Systems from the University of the West of England, Bristol in 1995 after completing an HND in Computing in 1993.

You may also be interested in...


Comments and Discussions

GeneralMy Thanks as well Pin
Mike Gaskey11-Jul-06 15:32
memberMike Gaskey11-Jul-06 15:32 
I just wanted to take a minute to thank you for your vision of a progress control. It met my needs perfectly.

Dear NYT - the fact is, the founding fathers hung traitors.

GeneralMFC Pin
장종석15-Jun-02 4:55
member장종석15-Jun-02 4:55 
GeneralThanks! Pin
Kevin Pinkerton10-Jul-01 3:32
memberKevin Pinkerton10-Jul-01 3:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.180111.1 | Last Updated 1 Dec 2000
Article Copyright 2000 by Craig Henderson
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid