Link to home
Start Free TrialLog in
Avatar of cosminm
cosminm

asked on

OnTimeChange

How can I intercept a system time change to get the difference occured?
Avatar of aikimark
aikimark
Flag of United States of America image

1. create your time-change monitor as a service
2. look at the call-back API documentation for the time change message.
Avatar of Summa
Summa

from Windows-SDK-Help

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

You will need to capture the system time on a regular basis in order to compare for the changed time difference calculation.
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;
Avatar of cosminm

ASKER

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?
ASKER CERTIFIED SOLUTION
Avatar of DrDelphi
DrDelphi

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of cosminm

ASKER

The example is wrong because the difference is padded with timer interval...
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.
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
Avatar of cosminm

ASKER

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...
Avatar of cosminm

ASKER

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...
Avatar of cosminm

ASKER

Seems to be not other solution than the one with a global variable...
Thanks guys anyway...
DrDelphi u've got the points...
Avatar of cosminm

ASKER

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!
cheers