Solved

real time clock in VC++

Posted on 1997-06-11
2
848 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
error email attachment VB2010 5 39
Winform not working on 64 bit machine 31 100
GUI: DIalog Stacking and Popping in MS C++ 4 76
Best book to learn C++ 4 79
This article shows a few slightly more advanced techniques for Windows 7 gadget programming, including how to save and restore user settings for your gadget and how to populate the "details" panel that is displayed in the Windows 7 gadget gallery.  …
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…
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

809 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