Economiseur et veille ecran

michelroc Messages postés 84 Date d'inscription lundi 19 mai 2003 Statut Membre Dernière intervention 2 janvier 2010 - 5 janv. 2006 à 20:40
neodelphi Messages postés 442 Date d'inscription jeudi 4 avril 2002 Statut Membre Dernière intervention 11 août 2008 - 8 janv. 2006 à 11:26
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.

5 réponses

neodelphi Messages postés 442 Date d'inscription jeudi 4 avril 2002 Statut Membre Dernière intervention 11 août 2008
6 janv. 2006 à 06:52
Si tu parle des paramètres de l'écran de veille c'est a toi de les sauvegarder dans un fichier puis de les charger.

neodelphi
0
michelroc Messages postés 84 Date d'inscription lundi 19 mai 2003 Statut Membre Dernière intervention 2 janvier 2010
6 janv. 2006 à 18:15
Ces parametres peut-on les modifier dans la base de registre

Michel
0
neodelphi Messages postés 442 Date d'inscription jeudi 4 avril 2002 Statut Membre Dernière intervention 11 août 2008
7 janv. 2006 à 06:59
Tu doit pouvoir le faire, mais pourquoi ne pas enregistrer dans un fichier ? c'est tellement plus simple lol.

neodelphi
0
michelroc Messages postés 84 Date d'inscription lundi 19 mai 2003 Statut Membre Dernière intervention 2 janvier 2010
7 janv. 2006 à 20:21
Bon alors j'ai ecris ce qui suis
Le fichier je le lance au demarrage du PC je par la cle HKEY_LOCAL_MACHINE\....\....\...\RUN

Je constate que le fichier m'est pas lu correctement ??? j'ai la valeur 600 pour V1 alors que dans mon ficheir *.TXT j'ai mis 30

Le code:

// Mise en fonction Economiseur et(ou) veille ECRAN
// ROCHER MIchel le 07/01/2006 [mailto:michel.rocher.1@cegetel.net michel.rocher.1@cegetel.net]
// Windows XP Fam
// DELPHI 2005
// Fichier A mettre sous C:\Windows\System32\MR_MARCHE_MEV.EXE
// Fichier Associé A mettre sous C:\Windows\System32\MR_CONFIG_MEV.TXT
// Les 2 premieres lignes de ce fichier *.TXT doivent contenir les valeurs
// Temps Economiseur et temps pour mise en vielle.
// Temps Ecran Veille; // Mini/Maxi 0-599940 9999 mn
// Temps Extinction Ecran // Maxi/Maxi 0-18000 5h00
// Mise en service:
// - Mettre dans fichier de demarrage ou
// - Uiliser le fichier Modif Base de registre
// HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\run


program MR_MARCHE_MEV;
{$APPTYPE CONSOLE}
uses
SysUtils,Messages,
ShellApi,Dialogs,
Windows;
Var F : TextFile;
V1,V2 : String;
i : Integer;
begin
// Lecture du fichier text contenant les 2 valeur V1 et V2
AssignFile(F, 'c:\Windows\System32\MR_CONFIG_MEV.TXT');
{$I-}
Reset(F);
{$I+}
If (IOResult=0) Then
Begin
V1:=''; // Temps Economiseur
V2:=''; //Temps Extinction Ecran
Readln(F,V1);
Readln(F,V2);
CloseFile(f);
// Teste si contenu est Numerique sinon Force à 600
If V1 = '' then V1 := '700';
For i:=1 to Length(V1) Do
If NOT(V1[i] In['0'..'9']) Then V1 := '600';
// Teste si contenu est numerique sinon force a 0
If V2 = '' then V2 := '0';
For i:=1 to Length(V2) Do
If NOT(V2[i] In['0'..'9']) Then V2 := '0';
// Ici Test du contenu V1 et V2 avec limites
If (StrToInt(V1)> 599940) Or (StrToInt(V1)< 0) Then V1 := '600';
If (StrToInt(V2)> 18000) Or (StrToInt(V2)< 0) Then V2 := '0';
// Active Ecomomiseur ecran
SystemparametersInfo(SPI_SETSCREENSAVEACTIVE,1,nil,SPIF_SENDWININICHANGE);
SystemparametersInfo(SPI_SETSCREENSAVETIMEOUT,StrToInt(V1),nil,SPIF_SENDWININICHANGE);
// Active Ecran vielle
SystemparametersInfo(SPI_SETPOWEROFFACTIVE,1,nil,SPIF_SENDWININICHANGE);
SystemparametersInfo(SPI_SETPOWEROFFTIMEOUT,StrToInt(V2),nil,SPIF_SENDWININICHANGE);
End;
Halt;
end.


Michel
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
neodelphi Messages postés 442 Date d'inscription jeudi 4 avril 2002 Statut Membre Dernière intervention 11 août 2008
8 janv. 2006 à 11:26
Si tu as 600 c'est que tu détecte pas V1 comme entier.



For i:=1 to Length(V1) Do

If NOT(V1[i] In['0'..'9']) Then V1 := '600';



Peut-être que le dernier caractère de V1 est un retour chariot, mais je
ne suis pas sur. Essaye de forcer la conversion en entier de V1, pour
voir si tu déclenche une exception.

neodelphi
0
Rejoignez-nous