?
Solved

OnTimeChange

Posted on 2002-03-27
14
Medium Priority
?
469 Views
Last Modified: 2007-12-19
How can I intercept a system time change to get the difference occured?
0
Comment
Question by:cosminm
[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
  • 6
  • 3
  • 3
  • +2
14 Comments
 
LVL 46

Expert Comment

by:aikimark
ID: 6901173
1. create your time-change monitor as a service
2. look at the call-back API documentation for the time change message.
0
 
LVL 1

Expert Comment

by:Summa
ID: 6902152
from Windows-SDK-Help

An application sends the WM_TIMECHANGE message to all top-level windows after changing the system time

0
 
LVL 46

Expert Comment

by:aikimark
ID: 6902507
You will need to capture the system time on a regular basis in order to compare for the changed time difference calculation.
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.

 
LVL 6

Expert Comment

by:DrDelphi
ID: 6902892
type
  TForm1 = class(TForm)
  private
    procedure Timechanged(var msg:TMessage);message WM_TIMECHANGE;
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Timechanged(var msg: TMessage);
begin
    showmessage('Time Changed');
end;
0
 

Author Comment

by:cosminm
ID: 6903648
Nice example DrDelphi for capturing the message, but I need to obtain the difference time ocured at the time change moment. Any ideas or examples, please...
Aikimark, do u have an example?
0
 
LVL 6

Accepted Solution

by:
DrDelphi earned 450 total points
ID: 6903668
The only solution that seems workable is to have a timer which does nothing but update a global variable with the current time.Then compare that variable to the new time in the message handler. For example:

type
 TForm1 = class(TForm)
    Timer1: TTimer;
    procedure Timer1Timer(Sender: TObject);
 private
   procedure Timechanged(var msg:TMessage);message WM_TIMECHANGE;
   { Private declarations }
 public
    Currenttime:TDateTime;
   { Public declarations }
 end;

var
 Form1: TForm1;

implementation

{$R *.DFM}


procedure TForm1.Timechanged(var msg: TMessage);
var oldTime,newTime:string;
begin
   OldTime:=TimeToStr(CurrentTime);
   newTime:=TimeTostr(now);
   ShowMessage(OldTime+#13+Newtime);
   end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  CurrentTime:=now;
end;

0
 

Author Comment

by:cosminm
ID: 6903687
The example is wrong because the difference is padded with timer interval...
0
 
LVL 46

Expert Comment

by:aikimark
ID: 6903755
this might get a little tricky.  You have to check for a time-change message when the timer pops.  I'd recommend two time variables (or two item array).  This should accomodate the possible collision between a timer event and the time change message.

Depending on the circumstance, you might have to create a timer using a Win API (callback), if you are going to do this as a (formless) service.
0
 
LVL 3

Expert Comment

by:SteveWaite
ID: 6906366
Use GetTickCount which gives the number of tics since the system started, 'not' the time of day.
Get the tick count on WM_TIMECHANGE subtract
the earlier tickcount from the just triggered count and you have the difference.

Regards,
Steve
0
 

Author Comment

by:cosminm
ID: 6906726
SteveWaite, seems to be an excelent solution...
But you have an example with GetTickCount (i haven't used before)...
And u'll get the points...
0
 

Author Comment

by:cosminm
ID: 6906808
Whops, is not a good solution 'cause the GetTickCount expire after about 50 days on Win9x and over that the function is not influenced by time changing... so no substract possible.
Waiting for another solution...
0
 

Author Comment

by:cosminm
ID: 6907005
Seems to be not other solution than the one with a global variable...
Thanks guys anyway...
DrDelphi u've got the points...
0
 

Author Comment

by:cosminm
ID: 6907866
Bug or what?! On WinNT-2000 all platforms works perfect the WM_TIMECHANGE event but on Win9x doesn't respond on system change! Or sometimes happens to capture the event twice!
What's happening? Please!
0
 
LVL 6

Expert Comment

by:DrDelphi
ID: 6909543
cheers
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses
Course of the Month10 days, 3 hours left to enroll

762 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