Solved

real time clock in VC++

Posted on 1997-06-11
2
852 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article surveys and compares options for encoding and decoding base64 data.  It includes source code in C++ as well as examples of how to use standard Windows API functions for these tasks. We'll look at the algorithms — how encoding and decodi…
What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
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…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

726 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