|
Home
Research
C++ Programming
Image Processing
Longest Common Subsequence
Spin Lock
Time to Complete Progress Control
Timed Update Edit Control
Personal
Recommended Reading
Links
|
Introduction
|
Progress bars are great for giving feedback to the user during
length operations. However, sometimes a percentage complete is not
enough, so I came up with this little class to display an estimation
of 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 time 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";
else
str.Format("%d second%s remaining", nSeconds, nSeconds==1? "":"s");
}
else
{
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;
}
Features
- Horizontal and Vertical progress bars are supported
- Smooth and Blocked progress bars are supported
- Expandable for custom text formatting
- Interchangable with MFC's
CProgressCtrl
- It's free !
Notes
The progress control uses Keith
Rule's Memory
DC class for smooth painting.
|
|
|
Permission to use, copy, modify, distribute and sell this software
and its documentation for any purpose is hereby granted without
fee, provided that the above copyright notice appears in all copies
and that both that copyright notice and this permission notice appear
in supporting documentation. The author makes no representations
about the suitability of this software for any purpose. It is provided
"as is" without express or implied warranty.
|
|