System Delphi

Title: How to create a screen saver
Question: How to create a screen saver
Answer:
How to create a simple Screen saver ?
************************************
It's realy easy juste copy/past this code :o)
And rename the ".exe" in ".scr"
//MWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMW
//With Project|View source
program SSave;
uses
Forms,SysUtils,
UFSave in 'UFSave.pas' {FVeille},
UFConfig in 'UFConfig.pas' {FConfig};
{$R *.RES}
Var
Param:string;
begin
Param:=Uppercase(ParamStr(1));
If (param='/C') or (param='') then // if the user click on "Parameters" button
begin
Application.Initialize;
Application.CreateForm(TFConfig, FConfig);
Application.Run;
end
else if (param='/S') then
begin
Application.Initialize;
Application.CreateForm(TFSave, FSave);
Application.Run;
end;
end.
//MWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMW
unit UFConfig;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,Registry,
StdCtrls, Buttons;
type
TFConfig = class(TForm)
BtnAnnul: TBitBtn;
BtnOk: TBitBtn;
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure BtnOkClick(Sender: TObject);
procedure BtnAnnulClick(Sender: TObject);
private
Reg:TRegistry;
{ Dclarations prives }
public
{ Dclarations publiques }
end;
var
FConfig: TFConfig;
implementation
{$R *.DFM}
procedure TFConfig.FormCreate(Sender: TObject);
begin
Reg:=TRegistry.create;
Reg.RootKey:=HKEY_LOCAL_MACHINE;
Try //Read parameters
//Reg.OpenKey('\SOFTWARE\'+{'Key name'},True); // "True" create teh key
//{Objet.Property} := Reg.ReadInteger({'KeyValues name'});
Except //Write default parameters
//{Objet.Property} :={'Default Values'};
//Reg.WriteInteger({'KeyValues name'},{Default Values});
End;
end;
procedure TFConfig.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Reg.free; //Free memory
end;
procedure TFConfig.BtnOkClick(Sender: TObject);
begin
Try //Write parameters
//Reg.OpenKey('\SOFTWARE\'+{'Key name'},True); // "True" create the key
//Reg.WriteInteger({'KeyValues name'},{Objet.Property});
Except
messagedlg('Error ?',mterror,[mbYes],0);
End;
Close;
end;
procedure TFConfig.BtnAnnulClick(Sender: TObject);
begin
Close;
end;
end.
//MWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMWMW
unit UFSave;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Registry, ExtCtrls;
type
FSave = class(TForm)
Timer1: TTimer;
procedure FormClick(Sender: TObject);
procedure FormKeyPress(Sender: TObject; var Key: Char);
procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure FormCreate(Sender: TObject);
private
{ Dclarations prives }
Reg:TRegistry;
public
X0,Y0:integer;
{ Dclarations publiques }
end;
var
FSave: TFSave;
implementation
{$R *.DFM}
procedure TFSave.FormClick(Sender: TObject);
begin
Close; //On quitte si on click
end;
procedure TFSave.FormKeyPress(Sender: TObject; var Key: Char);
begin
Close; //On quitte si on appuie sur une touche
end;
procedure TFSave.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
Const
Sensibilite:integer=0; //0 : Tres sensible
//100: Tres peu sensible ==Faire le test
begin
If ((x0-x)Sensibilite) or ((y0-y)Sensibilite) then //On quitte si la souris bouge
close ; //Avantage de cette routine : possibilit de paramtrer
//la sensiblilit de la souris !
x0:=x;
y0:=y;
end;
procedure TFSave.FormCreate(Sender: TObject);
begin
Screen.Cursor := crnone; //Desactivation du curseur de souris
Reg:=TRegistry.create;
Reg.RootKey:=HKEY_LOCAL_MACHINE; //Lecture de la base de registre
Try
//Reg.OpenKey('\SOFTWARE\'+{'Nom de la clef'},True); //Le "True" cre la clef si elle n'existe pas
//{Objet.Proprit ou Variable} := Reg.ReadInteger({'Nom de la variable'});
{ Ici pas obligation de concordance entre le nom de la variable en lecture
et de celle en critrure }
Except
//{Objet.Proprit} := {Valeur par defaut};
//Reg.WriteInteger({'Nom de la variable'},{Valeur par defaut});
End;
Reg.free
{Add your code here}
end;
end.