Solved

real time clock in VC++

Posted on 1997-06-11
2
846 Views
Last Modified: 2013-12-04
Hi,

Hi,

I want to write a program in Visual C++ 5.0 using MFC, which uses some kind of "real time clock".

Ok, when the program starts, the clock should start with time unit 0. Then it should count the time units in 1/10 of a second.

From my experiences with Java, I thought about using a thread, in which the clock will run. It should only count the time units and return the current, when asked for.
The main thread would then do the main work and whenever something new must be done, it should call the clock to ask for the "time". If the time is right, the next thing can be done.

Another idea is to use the function "_ftime" which returns the current time, I guess. The problem then can be the necessary calculation to do to translate the time struct to the appropriate time units. I think, this needs too much time.

It would be nice, if you could tell me which way would be the easiest(using threads, _ftime or another). It would be fine too, if you could give an example by including some example source code.

Thanks in advance, re.
0
Comment
Question by:re
2 Comments
 
LVL 23

Accepted Solution

by:
chensu earned 100 total points
ID: 1398168
I think the easiest way is to call Win32 Multimedia function timeGetTime(). The timeGetTime function retrieves the system time, in milliseconds. The system time is the time elapsed since Windows was started. Its default precision is enough for your case. When your program starts, call timeGetTime() to record the starting time
m_dwStart = ::timeGetTime();

When you need the current time unit, do the following
DWORD dwUnit = (::timeGetTime() - m_dwStart) / 100;

0
 

Author Comment

by:re
ID: 1398169
I checked the function "timeGetTime" in a small console application and it seems to run fast enough, for what I have to do.

Thanks for your help again, re.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now