Vous ne trouvez pas de réponse à votre problème ? Alors posez la question dans le forum. Souvenez-vous qu'il n'y a jamais de question bête, mais rester dans l'ignorance parce que l'on n'ose pas poser une question, ça c'est une erreur !

CHANGEMENT AUTOMATIQUE DE L'IMAGE DE L'ARRIÈRE PLAN LORS DU DÉMARAGE DU WINDOWS


Information sur la source

Catégorie :API Niveau : Initié Date de création : 13/09/2002 Date de mise à jour : 13/09/2002 19:58:21 Vu / téléchargé: 3 608 / 183

Note :
Aucune note

Commentaire sur cette source (3)
Ajouter un commentaire et/ou une note

Description

Hello, I am Ameziane Rabie. This program let us make our Desktop background image always change every time when Windows starts. You just specify the directory that contains all your pictures and you will have every day a new background picture set automaticaly.


 

Source

  • program WallPaper;
  • uses
  • SysUtils, FileCtrl, Windows, Registry;
  • {$R *.RES}
  • var
  • Directory, FirstFile: String;
  • PictureIndex: Integer;
  • i: Integer;
  • Info: TSearchRec;
  • FileFound: Boolean;
  • Reg: TRegistry;
  • begin
  • if ParamCount=2 then
  • begin
  • // Windows executes the program when it starts sending tow parameters
  • Directory:=ParamStr(1);
  • PictureIndex:=StrToInt(ParamStr(2));
  • if DirectoryExists(Directory) then
  • begin
  • i:=0;
  • FileFound:=False;
  • if FindFirst(Directory + '*.bmp', faArchive, Info)=0 then
  • begin
  • FirstFile:=info.Name;
  • // Search of picture file in directory
  • repeat
  • Inc(i);
  • if PictureIndex = i then
  • begin
  • FileFound:=True;
  • SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, PChar(Directory+Info.Name), SPIF_UPDATEINIFILE);
  • if FindNext(Info) = 0 then Inc(PictureIndex) else PictureIndex:=1;
  • end;
  • until (FindNext(Info) <> 0) or FileFound;
  • // Set first picture file existing in directory
  • // as Wallpaper if index picture doesn't exist
  • if not FileFound then
  • begin
  • SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, PChar(Directory+FirstFile), SPIF_UPDATEINIFILE);
  • PictureIndex:=2;
  • end;
  • // Set next picture's index in the Registry Windows
  • Reg:=TRegistry.Create;
  • try
  • Reg.RootKey := HKEY_LOCAL_MACHINE;
  • if Reg.OpenKey('\Software\Microsoft\Windows\CurrentVersion\Run', True) then
  • Reg.WriteString('WallPaper', ParamStr(0)+' '+Directory+' '+IntToStr(PictureIndex));
  • finally
  • Reg.CloseKey;
  • Reg.Free;
  • end;
  • end;
  • end;
  • end else
  • begin
  • // User executes the program
  • // Select directory of user's pictures
  • if SelectDirectory('Select Pictures Directory', '', Directory) then
  • begin
  • if Length(Directory)<>3 then Directory:=Directory+'\';
  • Reg:=TRegistry.Create;
  • try
  • Reg.RootKey := HKEY_LOCAL_MACHINE;
  • if Reg.OpenKey('\Software\Microsoft\Windows\CurrentVersion\Run', True) then
  • Reg.WriteString('WallPaper', ParamStr(0)+' '+Directory+' 1');
  • finally
  • Reg.CloseKey;
  • Reg.Free;
  • end;
  • end;
  • end;
  • end.
program WallPaper;

uses
  SysUtils, FileCtrl, Windows, Registry;

{$R *.RES}
var
  Directory, FirstFile: String;
  PictureIndex: Integer;
  i: Integer;
  Info: TSearchRec;
  FileFound: Boolean;
  Reg: TRegistry;

begin
  if ParamCount=2 then
  begin
    // Windows executes the program when it starts sending tow parameters

    Directory:=ParamStr(1);
    PictureIndex:=StrToInt(ParamStr(2));
    if DirectoryExists(Directory) then
    begin
      i:=0;
      FileFound:=False;
      if FindFirst(Directory + '*.bmp', faArchive, Info)=0 then
      begin
        FirstFile:=info.Name;

        // Search of picture file in directory
        repeat
          Inc(i);
          if PictureIndex = i then
          begin
            FileFound:=True;
            SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, PChar(Directory+Info.Name), SPIF_UPDATEINIFILE);
            if FindNext(Info) = 0 then Inc(PictureIndex) else PictureIndex:=1;
          end;
        until (FindNext(Info) <> 0) or FileFound;

        // Set first picture file existing in directory
        // as Wallpaper if index picture doesn't exist
        if not FileFound then
        begin
          SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, PChar(Directory+FirstFile), SPIF_UPDATEINIFILE);
          PictureIndex:=2;
        end;

        // Set next picture's index in the Registry Windows
        Reg:=TRegistry.Create;
        try
          Reg.RootKey := HKEY_LOCAL_MACHINE;
          if Reg.OpenKey('\Software\Microsoft\Windows\CurrentVersion\Run', True) then
            Reg.WriteString('WallPaper', ParamStr(0)+' '+Directory+' '+IntToStr(PictureIndex));
        finally
          Reg.CloseKey;
          Reg.Free;
        end;
      end;
    end;
  end else
  begin
    // User executes the program

    // Select directory of user's pictures
    if SelectDirectory('Select Pictures Directory', '', Directory) then
    begin
      if Length(Directory)<>3 then Directory:=Directory+'\';
      Reg:=TRegistry.Create;
      try
        Reg.RootKey := HKEY_LOCAL_MACHINE;
        if Reg.OpenKey('\Software\Microsoft\Windows\CurrentVersion\Run', True) then
          Reg.WriteString('WallPaper', ParamStr(0)+' '+Directory+' 1');
      finally
        Reg.CloseKey;
        Reg.Free;
      end;
    end;
  end;
end.

Conclusion

Compile the source 'WallPaper.dpr' then execute it to select the directory that includes all your Bitmap pictures. Every time when you start Windows you will have new picture on you DeskTop.

 

Commentaires et avis

signaler à un administrateur
Commentaire de cariboo le 24/02/2003 14:05:56

ici on est sur un site francophone...

signaler à un administrateur
Commentaire de Arkko le 06/04/2003 06:28:56

Im not sure you see that but you are on delphi FRANCE ... in french people speak FRENCH !!!

signaler à un administrateur
Commentaire de medellelabdesselem le 03/12/2007 21:12:44

merci boucoup mon frere

Ajouter un commentaire



Nos sponsors

Sondage...

CalendriCode

Octobre 2008
LMMJVSD
  12345
6789101112
13141516171819
20212223242526
2728293031  

Consulter la suite du CalendriCode

Appels d'offres



Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel BAÏSE, Merci à Vincent pour ses précieux conseils
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés
Temps d'éxécution de la page : 0,172 sec

Google Coop CodeS-SourceS Google Coop CodeS-SourceS


Certaines images présentes sur le site (notament certains avatars) sont issues des collections IconShock, donc si vous souhaitez utiliser ces icons vous devez les acheter, ne les copiez pas et ne utilisez pas dans vos sites et applications sans les avoir commandé.