WinAsm Studio, The Assembly IDE - Free Downloads, Source Code
Sponsors
Articles
Programming Quick Start
32-bit Assembler is Easy
Porting Iczelion tutorials
What is FASM
Hard Drive Recovery
Wiring your own LAN
Personal menu
Welcome Guest
User:
Pass:
Register!
Resend Validation Email
 
Forum
Pages (3) [1] 2 3   ( Go to first unread post )

Incremental timer - day hour minute second, how to make a very precise timer? Using GetLocalTime or GetSystemTime and substracting the days is not straight forward.

LaHire
Quote Post


Active Member
***

Group: Members
Posts: 44
Member No.: 5774
Joined: 15-February 08


What is the best way to make a time counter that increase every second; something displayed on a dialog box like DD HH:MM:SS (00 00:00:00 then 00 00:00:01 and so on)?

I thought about using WM_TIMER but I wonder if this timer is very accurate in long term (I mean for seconds it may be OK but as for days I do not know). So I was also thinking about using GetLocalTime or GetSystemTime but if I substract:
Actualtime.wDay - StartingDay.wDay
I may have a problem to calculate the delay between 2 days (day '1' - day '29' for instance) since months can have 28, 29, 30 or 31 days. In addition if someone for a reason or another change the time (or during an automatic change of hour) the result will not be good.

So if someone has a good suggestion or knows how to make a very precise* timer I am interested. Maybe WM_TIMER is good enough...



* : I mean after 10 days 00:00:00 it is really displayed 10 days 00:00:00.
PM
Top
akyprian
Quote Post


Administrator
******

Group: Admins
Posts: 2307
Member No.: 1
Joined: 12-May 04


Consider using QueryPerformanceCounter at application startup and QueryPerformanceCounter and QueryPerformanceFrequency API's in WM_TIMER. By this means, You would get a precise timer.

I hope it helps
PMEmail PosterUsers Website
Top
LaHire
Quote Post


Active Member
***

Group: Members
Posts: 44
Member No.: 5774
Joined: 15-February 08


QUOTE (akyprian @ Feb 27 2008, 09:06 AM)
Consider using QueryPerformanceCounter at application startup and QueryPerformanceCounter and QueryPerformanceFrequency API's in WM_TIMER. By this means, You would get a precise timer.

I hope it helps

That is an idea. However "QueryPerformanceCounter" needs a hardware configuration (otherwise the function return 0).

From your experience did you try to use a WM_TIMER that increments (let's say every second) a counter for a long time and noticed a difference between its value and the time? This is just a question of accuracy.
PM
Top
akyprian
Quote Post


Administrator
******

Group: Admins
Posts: 2307
Member No.: 1
Joined: 12-May 04


I haven't tried WM_TIMER the way you ask, but I have observed that by other methods. In addition, from microsoft ...Because WM_TIMER messages are processed at a low priority, somewhat like WM_PAINT messages, they are often delayed while other messages are processed...

Regards
PMEmail PosterUsers Website
Top
Ratch
Quote Post


New Member
*

Group: Members
Posts: 17
Member No.: 5803
Joined: 8-March 08


LaHire,
QUOTE
What is the best way to make a time counter that increase every second; something displayed on a dialog box like DD HH:MM:SS (00 00:00:00 then 00 00:00:01 and so on)?


I think you are referring to a clock. Charles Petzold has two clock programs (digital and analog) in his book Programming Windows, Edition 5. His clocks do hours, min, and secs, but you should not have too much trouble modifying it. I am sending you the executable of the digital clock I transcribed into MASM. If you are interested in the MASM code I wrote, I can send it also. It uses the GetLocalTime API, which is as accurate as your CPU's time clock is. Ratch

Attached File ( Number of downloads: 42 )
 Login or Register to download
PMEmail Poster
Top
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

Topic Options Pages (3) [1] 2 3  Reply to this topicStart new topicStart Poll

 

Sponsors
Computer Science

Internet
C/C++
Hardware & PC maintenance

HiEditor

General Discussions
Suggestions/Bug Reports
WinAsm Studio

General Discussions
Suggestions/Bug Reports
WinAsm Studio FAQ
Multilingual User Interface
Add-Ins
Assembly Programming

Main
Newbies
Projects
Custom Controls
Snippets
Announcements & Rules

Announcements

General

Online Degrees - Distance Learning
The Heap
Russian
Google