cosminm
asked on
OnTimeChange
How can I intercept a system time change to get the difference occured?
from Windows-SDK-Help
An application sends the WM_TIMECHANGE message to all top-level windows after changing the system time
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;
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;
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?
Aikimark, do u have an example?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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
Get the tick count on WM_TIMECHANGE subtract
the earlier tickcount from the just triggered count and you have the difference.
Regards,
Steve
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...
But you have an example with GetTickCount (i haven't used before)...
And u'll get the points...
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...
Waiting for another solution...
ASKER
Seems to be not other solution than the one with a global variable...
Thanks guys anyway...
DrDelphi u've got the points...
Thanks guys anyway...
DrDelphi u've got the points...
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!
What's happening? Please!
cheers
2. look at the call-back API documentation for the time change message.