• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 489
  • Last Modified:

Stopwatch Function in C++

I am fairly new to C++ but I am attempting to write a time tracking program. THIS IS NOT HOMEWORK....  The concept is that I have a GUI with 10 tasks.  For each task there is a button that is to be used to start/stop time tracking for that particular task.  When the button is pressed initially the edit field for that task will start at 00:00:00 and show a running timer for that task to show the elapsed time for the task.  When the button is pressed again I will write the value to the registry and that will be used as the start time for that task.  I have tried everything that I could think of.  Is there a function that provides this capability?  Please help.  I have spent HOURS trying to figure this out.

Brent
0
bblevins
Asked:
bblevins
  • 3
  • 2
1 Solution
 
mimounetteCommented:

Is there a function that provides this capability?

Capability of what ? The whole solution or an api for writting in registry.
0
 
bblevinsAuthor Commented:
I know how to write and retrieve values from the registry. It is the stopwatch function that I have been unable to figure out.  Sorry I wasn't more clear.
0
 
mimounetteCommented:
To be sure, you want to initialize the clock when a user click on a button and stop it (write the result in registry) when the user hits one more time the button ?

When you said C++ do you mean Visual C++ ?

If it's that I will give you my answer.


0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
bblevinsAuthor Commented:
I am using Borland C++ Builder.  So it is just C++ not VC++

When the user clicks a button I want the clock to be initialized at 00:00:00.  If they press the button again, the clock should stop and the value written to the registry.  If the button is pressed a third time,  The clock should use the value previously written to the registry as the initialization value and continue to track time from that point.
0
 
mimounetteCommented:
Use a global variable that will take 3 different values

enum
{
 CLOCK_NOT_INITIALIZED = 0;
 CLOCK_INITIALIZED = 1;
 CLOCK_RUNNING = 2;
 CLOCK_STOPPED = 3;
};


Constructor:
int m_nTask0Status = CLOCK_NOT_INITIALIZED;

OnClick methode

switch(m_nTask0Status)
{
 case CLOCK_NOT_INITIALIZED:
    nTask0Status = CLOCK_INITIALIZED;
    RestetTimerTask();
    break;  

 case CLOCK_RUNNING:
    nTask0Status = CLOCK_STOPPED;
    StopTimerTask();
    WriteToRegistry(GetTimerValue());
    break;  

 case CLOCK_STOPPED:
    nTask0Status = CLOCK_RUNNIN;
    SetTimerValue(ReadFromRegsitry());
    break;  

 default:
   break;
}
0
 
CleanupPingCommented:
bblevins:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now