Click here to Skip to main content
Click here to Skip to main content
Go to top

CEstimateTimeStatic - a class for estimating remaining time

, 6 Feb 2003
Rate this:
Please Sign up or sign in to vote.
A simple but effective class for estimating remaining time in the execution of a process
<!-- Download Links --> <!-- Article image -->

Sample Image - CEstimateTimeStatic.jpg

<!-- 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

  1. Add EstimateTimeStatic.h and EstimateTimeStatic.cpp to your project.

  2. Drop a Static/label control on the dialog .

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

  4. 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.
         //{{AFX_DATA(CEstimateTimeSampleDlg)
        enum { IDD = IDD_ESTIMATETIMESAMPLE_DIALOG };
        CEstimateTimeStatic m_sEstimateTimeLeft;<P></P>     //}}AFX_DATA

     

  5. 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 : "); 
       //message to be displayed
       m_sEstimateTimeLeft.SetProcessSize(100*1024); 
       //set process size in KB for better resolution
  6. Call the function m_sEstimateTimeLeft.StartProcess () and start copying files :
    void CYourClass::CopySomeFiles(){
       ...
       ...
       m_sEstimateTimeLeft.StartProcess ();
       ...
       //start copying
       for (int nCount = 1;nCount <= nFilesNumber ; nCount++)<P></P>   {
        //copy  file  
         m_sEstimateTimeLeft.OffsetProcessPosition(file size(in kilobytes));
         if   (//we need to display some confirmation//)
         {
            m_sEstimateTimeLeft.PauseProcess();
            //display confirmation (the confirmation window is supposed to be modal, <BR>        //so the execution of the process stops)
            m_sEstimateTimeLeft.ResumeProcess();
          }
       
       }
    }<BR>
  7. Don't forget to call m_sEstimateTimeLeft.StopProcess()
    void  CYourClass::CopySomeFiles()
       {
         ...
         ...
         m_sEstimateTimeLeft.StopProcess (); 
       }
    

Acknowledgements

  • Robert Brault - For using code from his class CColorStatic.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Doru Cioata
Web Developer
Romania Romania
Still a student at a computer science related faculty in the University of Craiova, Romania :Frown | :(
Hope that one day I'll graduate! Smile | :) ). Programming for last 8 years (Visual C++ for the last 2 years).

Comments and Discussions

 
Questionwhy is it not working for large numbers 56800235584 Pinmemberv_srinu_26_f1-Feb-07 2:27 
GeneralThanks for the Props PinmemberRobert Brault3-Jan-04 8:47 
Generalthose are some horrible colors Pinmemberector10-Feb-03 4:04 
GeneralRe: those are some horrible colors Pinmemberconrad Braam3-Jan-10 2:53 

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

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

| Advertise | Privacy | Mobile
Web04 | 2.8.140922.1 | Last Updated 7 Feb 2003
Article Copyright 2003 by Doru Cioata
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid