- 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.