Ver Mensaje Individual
  #17  
Antiguo 12-08-2006
Avatar de Lepe
[Lepe] Lepe is offline
Miembro Premium
 
Registrado: may 2003
Posts: 7.424
Reputación: 28
Lepe Va por buen camino
Otra Opción sería crear un servicio / programa oculto que le notifiquen cuando el usuario cambie la hora del sistema. Muestras un mensaje en pantalla y si tu programa está funcionando, puedes sacar un mensaje en pantalla poniendo verde al usuario .

Código Delphi [-]
// Lepes Comments:
// - tested and It Works !! ;-)

//Knowing when the system date or time has changed
//Author: The Baker    Date Entered: 2002-04-09  ID: 19   Sections: [ Delphi ]
//
//If you need to know if the system date or time has changed you can simply
// intercept the WM_TIMECHANGE Window message. This message will be called when
// the time is set.
//
//The following is the code for a component that will trap the WM_TIMECHANGE
//window message and then fire a OnTimeChange notify event, similar to TTimer.


//Extra note: If you double click on the time in the task bar the "Date/Time
//Properties" dialogue will be displayed. If you click the OK button without
//making any alterations to the date or time, the WM_TIMECHANGE message will
//still fire. Not really what you would expect.


Unit UTimeChange;

interface

Uses
   Classes, Windows, Messages, Forms;

Type
   TTimeChange = class(TComponent)
   private
     FWindowHandle: HWND;
     FOnTimeChange: TNotifyEvent;
     FEnabled: Boolean;

     procedure WndProc(var Msg: TMessage);
   protected
     procedure TimeChange; dynamic;
   public
     constructor Create(AOwner: TComponent); override;
     destructor Destroy; override;
   published
     property Enabled: Boolean read FEnabled write FEnabled default True;
     property OnTimeChange: TNotifyEvent read FOnTimeChange write FOnTimeChange;
   end;

//procedure Register;

implementation

{ TTimeChange }

constructor TTimeChange.Create(AOwner: TComponent);
begin
   inherited Create(AOwner);

   FEnabled := True;
   FWindowHandle := Classes.AllocateHWnd(WndProc);
end;

destructor TTimeChange.Destroy;
begin
   FEnabled := False;
   Classes.DeallocateHWnd(FWindowHandle);

   inherited Destroy;
end;

procedure TTimeChange.WndProc(var Msg: TMessage);
begin
   with Msg do Begin
     if FEnabled and (Msg = WM_TIMECHANGE) then
       try
         TimeChange;
       except
         Application.HandleException(Self);
       end
     else
       Result := DefWindowProc(FWindowHandle, Msg, wParam, lParam);
   End; {end With}
end;

procedure TTimeChange.TimeChange;
begin
   if Assigned(FOnTimeChange) then FOnTimeChange(Self);
end;

//procedure Register;
//begin
//   RegisterComponents('CodeBake', [TTimeChange]);
//end;

end.

No he mirado si tambien lo detecta en el DOS, además podría reiniciar la máquina entrar en modo DOS y cambiar la fecha, pero bueno, esos temas se han tratado anteriormente.

Edito: He puesto con comentarios el procedure Register, ya que no me gusta tenerlo en la paleta de componentes de Delphi, sino tenerlo en el Library Path y crearlo por código como si fuera un objeto más. Si quieres tenerlo en la paleta, pues quita los comentarios de dicho procedure.

Aunque el código es antiguo, no disponía de él cuando se originó este hilo.

Saludos y suerte.
__________________
Si usted entendió mi comentario, contácteme y gustosamente,
se lo volveré a explicar hasta que no lo entienda, Gracias.

Última edición por Lepe fecha: 12-08-2006 a las 09:41:36.
Responder Con Cita