Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 481
  • Last Modified:

OnTimeChange

How can I intercept a system time change to get the difference occured?
0
cosminm
Asked:
cosminm
  • 6
  • 3
  • 3
  • +2
1 Solution
 
aikimarkCommented:
1. create your time-change monitor as a service
2. look at the call-back API documentation for the time change message.
0
 
SummaCommented:
from Windows-SDK-Help

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

0
 
aikimarkCommented:
You will need to capture the system time on a regular basis in order to compare for the changed time difference calculation.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
DrDelphiCommented:
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
 
cosminmAuthor Commented:
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
 
DrDelphiCommented:
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
 
cosminmAuthor Commented:
The example is wrong because the difference is padded with timer interval...
0
 
aikimarkCommented:
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
 
SteveWaiteCommented:
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
 
cosminmAuthor Commented:
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
 
cosminmAuthor Commented:
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
 
cosminmAuthor Commented:
Seems to be not other solution than the one with a global variable...
Thanks guys anyway...
DrDelphi u've got the points...
0
 
cosminmAuthor Commented:
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
 
DrDelphiCommented:
cheers
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 6
  • 3
  • 3
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now