Solved

OnTimeChange

Posted on 2002-03-27
14
454 Views
Last Modified: 2007-12-19
How can I intercept a system time change to get the difference occured?
0
Comment
Question by:cosminm
  • 6
  • 3
  • 3
  • +2
14 Comments
 
LVL 45

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 45

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
 
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 150 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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 45

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

744 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

10 Experts available now in Live!

Get 1:1 Help Now