<!-- Download Links -->
<!-- Article image -->

<!-- Add the rest of your HTML here -->
Overview
This article presents a CStatic derived class for
estimating and displaying remaining time. It also provides color
functionality (a lot of thanks to Robert Brault for his CColorStatic
class). Using this class is quite similar to using CProgressCtrl -
you set the process size and then ,as the process executes, you offset the
current position and knowing the current position in the process and the amount
of time spent it calculates the time left until the end of the process.
The class does not estimate ramaining time every time you offset, estimating being
done every 1 second. CEstimateTimeStatic
works also with processes that could be interrupted (ex. user
is asked for confirmation) and then resumed (the time interval
between displaying the confirmation and resuming the process after user makes
his choice doesn't count because this amount of time is not spent for ececuting
the process).
Usage
-
Add EstimateTimeStatic.h and EstimateTimeStatic.cpp to your
project.
-
Drop a Static/label control on the dialog .
-
Add a member variable for the particular static control. Give it the name (say
m_sEstimateTimeLeft) and select a category of type Control. This would make the
variable type
CStatic automatically.
-
Open your class and add the line #include "EstimateTimeStatic.h" on
top to include the declarations of the
CEstimateTimeStatic class.
Replace the class CStatic with CEstimateTimeStatic
in header file.
enum { IDD = IDD_ESTIMATETIMESAMPLE_DIALOG };
CEstimateTimeStatic m_sEstimateTimeLeft;<P></P>
-
Before you start executing the assigned process, initialize m_sEstimateTimeLeft :
Let's say that you want to copy some files with the total size of 100MB
-
set the message to be displayed
-
set the size of the process
m_sEstimateTimeLeft.SetMessageText("Estimated time left : ");
m_sEstimateTimeLeft.SetProcessSize(100*1024);
-
Call the function
m_sEstimateTimeLeft.StartProcess () and start
copying files :
void CYourClass::CopySomeFiles(){
...
...
m_sEstimateTimeLeft.StartProcess ();
...
for (int nCount = 1;nCount <= nFilesNumber ; nCount++)<P></P> {
m_sEstimateTimeLeft.OffsetProcessPosition(file size(in kilobytes));
if ( {
m_sEstimateTimeLeft.PauseProcess();
m_sEstimateTimeLeft.ResumeProcess();
}
}
}<BR>
-
Don't forget to call
m_sEstimateTimeLeft.StopProcess()
void CYourClass::CopySomeFiles()
{
...
...
m_sEstimateTimeLeft.StopProcess ();
}
Acknowledgements
-
Robert Brault - For using code from his class CColorStatic.