Faire apparaitre l'horloge une et une seule fois

Résolu/Fermé
lotfi213_b19 Messages postés 36 Date d'inscription dimanche 31 décembre 2006 Statut Membre Dernière intervention 31 juillet 2010 - 28 sept. 2007 à 15:40
Loulibier Messages postés 309 Date d'inscription jeudi 6 juin 2002 Statut Membre Dernière intervention 24 septembre 2008 - 28 sept. 2007 à 16:24
EXECUTER ET VOIR
Comment faire apparaitre l'horloge une et une seule fois!
aidez moi s'il vous plait

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls;

type
TForm1 = class(TForm)
Timer1: TTimer;
procedure Timer1Timer(Sender: TObject);
private
{ Déclarations privées }
public
{ Déclarations publiques }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Timer1Timer(Sender: TObject);
var
TheForeGround:THandle;
CaptionFocused:Array [0..255]of char;
text:string;
begin
TheForeGround:=GetForegroundWindow;
GetWindowText(TheForeGround,CaptionFocused,256);
form1.Caption:=CaptionFocused;
text:=timetostr(time);
SetWindowText(TheForeground,Strcat(CaptionFocused,PChar(text)));
end;

end.

1 réponse

Loulibier Messages postés 309 Date d'inscription jeudi 6 juin 2002 Statut Membre Dernière intervention 24 septembre 2008 2
28 sept. 2007 à 16:24
Bonjour lofti213_b19

voici une technique qui te permettra d'avoir qu'une seule fois l'heure d'affiché.
Il faut que tu déclares une function qui va te reformater la titre de ta fenetre sans l'heure...

function GetCaptionWithoutTime(const sCaption : string): PChar;
var
  sTime  : string;
  dtTime : TDateTime;
begin
  sTime := Copy(sCaption, Length(sCaption) - 7, 8);



  if not TryStrToTime(sTime, dtTime) then
    Result : = PChar(sCaption)
  else
    Result := PChar(Copy(sCaption, 1, Length(sCaption) - 8));
end ;  

procedure TForm1.Timer1Timer(Sender: TObject);
var
  TheForeGround:THandle;
  CaptionFocused:Array [0..255]of char;
  text:string;
begin
  TheForeGround: =GetForegroundWindow;
  GetWindowText(TheForeGround,CaptionFocused,256);
  form1.Caption:=CaptionFocused;
  text:=timetostr(time);
  SetWindowText(TheForeground,Strcat(GetCaptionWithoutTime(CaptionFocused),PChar(text)));
end;

Bonne Prog,  Olivier
PS : Lorsqu'une réponse vous convient, n'oubliez pas de la valider.
3
Rejoignez-nous