bonjour,
Apres avoir recuperer sur ce site les api pour economiseur et mise en veille ecran, cela fonctionne en partie . J'ai des problemes pour la prise en comptes des valeurs apres un reboot je retrouve les valeurs par defaut . Merci pour vos infos et Bonne année à tous Michel

unit Veille1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls, Mask, Spin;
type
TForm1 = class(TForm)
GroupBox1: TGroupBox;
GroupBox2: TGroupBox;
Label1: TLabel;
Label2: TLabel;
GroupBox3: TGroupBox;
CheckBox1: TCheckBox;
Button1: TButton;
Timer1: TTimer;
SpinEdit1: TSpinEdit;
GroupBox5: TGroupBox;
GroupBox6: TGroupBox;
GroupBox7: TGroupBox;
Button4: TButton;
CheckBox2: TCheckBox;
SpinEdit2: TSpinEdit;
Label3: TLabel;
Label6: TLabel;
procedure Button4Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure FormActivate(Sender: TObject);
private
{ Déclarations privées }
Procedure Test_Etat_Economiseur;
Procedure Test_Etat_Ecran_Veille;
public
{ Déclarations publiques }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormActivate(Sender: TObject);
Begin
Test_Etat_Economiseur;
Test_Etat_Ecran_Veille;
End;
Procedure TForm1.Test_Etat_Economiseur;
Var Temps ,mn:integer;
Actif:Boolean;
begin
Label1.Caption :='Economiseur Actif : ';
Label2.Caption :='Temps : ';
// Test si Economiseur ecran est actif
SystemparametersInfo(SPI_GETSCREENSAVEACTIVE,0,@Actif,SPIF_SENDWININICHANGE);
if Actif then Label1.Caption := Label1.Caption+' OUI'
else Label1.Caption := Label1.Caption+' NON';
// Temps de le mise en route de l'economiseur
SystemparametersInfo(SPI_GETSCREENSAVETIMEOUT,0,@Temps,SPIF_SENDWININICHANGE);
Label2.caption:=Label2.caption +IntToStr(Temps);
mn := Temps Div 60;
Label2.Caption := Label2.Caption + ' Secondes '+'('+IntToStr(mn)+' mn)';
SpinEdit1.Text := IntToStr(Temps);
If Actif then Begin
Label2.Enabled:=True;
CheckBox1.State:=cbChecked;
End
else Begin
Label2.Enabled:=False;
CheckBox1.State:=cbUnchecked;
End;
End;
Procedure TForm1.Test_Etat_Ecran_Veille;
Var T2 :integer;
Act:Boolean;
Begin
Label3.Caption :='Ecran Veille Actif : ';
Label6.Caption :='Temps : ';
// Test si ecran Veille est actif
SystemparametersInfo(SPI_GETPOWEROFFACTIVE,0,@Act,SPIF_SENDWININICHANGE);
if Act then Label3.Caption := Label3.Caption+' OUI'
else Label3.Caption := Label3.Caption+' NON';
// Temps de le mise en route de l'ecran veille
SystemParametersInfo(SPI_GETPOWEROFFTIMEOUT, 0, @T2,SPIF_UPDATEINIFILE);
Label6.caption:=Label6.caption +IntToStr(T2);
Label6.Caption := Label6.Caption + ' Minutes ';
SpinEdit2.Text := IntToStr(T2);
If Act then Begin
Label6.Enabled:=True;
CheckBox2.State:=cbChecked;
End
else Begin
Label6.Enabled:=False;
CheckBox2.State:=cbUnchecked;
End;
End;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
If CheckBox1.State = cbChecked Then CheckBox1.Caption := 'Activé l''économiseur'
Else CheckBox1.Caption := 'Désactivé l''économiseur';
If CheckBox2.State = cbChecked Then CheckBox2.Caption := 'Activé l''écran de veille'
Else CheckBox2.Caption := 'Désactivé l''écran de veille';
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
If SpinEdit1.text > '599940' then Spinedit1.Text := '600';
If CheckBox1.State = cbChecked Then
Begin
SystemparametersInfo(SPI_SETSCREENSAVEACTIVE,1,nil,SPIF_SENDWININICHANGE);
SystemparametersInfo(SPI_SETSCREENSAVETIMEOUT,StrToInt(SpinEdit1.Text),nil,SPIF_SENDWININICHANGE);
End
Else
Begin
SystemparametersInfo(SPI_SETSCREENSAVEACTIVE,0,nil,SPIF_SENDWININICHANGE);
SystemparametersInfo(SPI_SETSCREENSAVETIMEOUT,StrToInt(SpinEdit1.Text),nil,SPIF_SENDWININICHANGE);
End;
Test_Etat_Economiseur;
end;
procedure TForm1.Button4Click(Sender: TObject);
begin
If SpinEdit2.text > '300' then Spinedit2.Text := '300';
If CheckBox2.State = cbChecked Then
Begin
SystemparametersInfo(SPI_SETPOWEROFFACTIVE,1,nil,SPIF_SENDWININICHANGE);
SystemparametersInfo(SPI_SETPOWEROFFTIMEOUT,StrToInt(SpinEdit2.Text),nil,SPIF_SENDWININICHANGE);
End
Else
Begin
SystemparametersInfo(SPI_SETPOWEROFFACTIVE,0,nil,SPIF_SENDWININICHANGE);
SystemparametersInfo(SPI_SETPOWEROFFTIMEOUT,0,nil,SPIF_SENDWININICHANGE);
End;
Test_Etat_Ecran_Veille;
end;
end.