unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Borland.Vcl.Menus, Borland.Vcl.StdCtrls, Borland.Vcl.FileCtrl,
  Borland.Vcl.ExtCtrls, System.ComponentModel,
  System.Text, //StringBuilder
  System.Runtime.InteropServices; //Marshal

type
  TForm1 = class(TForm)
    Splitter1: TSplitter;
    Image1: TImage;
    Panel1: TPanel;
    DirectoryListBox1: TDirectoryListBox;
    FileListBox1: TFileListBox;
    Panel2: TPanel;
    DriveComboBox1: TDriveComboBox;
    PopupMenu1: TPopupMenu;
    Ustawjakotapetpulpitu1: TMenuItem;
    Zamknij1: TMenuItem;
    procedure FormResize(Sender: TObject);
    procedure FileListBox1DblClick(Sender: TObject);
    procedure Zamknij1Click(Sender: TObject);
    procedure FileListBox1Change(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.nfm}

procedure TForm1.FormCreate(Sender: TObject);
var
  katalog :StringBuilder;
begin
katalog:=StringBuilder.Create(MAX_PATH);
GetWindowsDirectory(katalog,MAX_PATH);
//if DirectoryExists(katalog.ToString+'\WEB\Wallpaper') then katalog.Append('\WEB\Wallpaper');
FileListBox1.Directory:=katalog.ToString;
end;

procedure TForm1.FileListBox1Change(Sender: TObject);
begin
if (FileListBox1.FileName<>'') and (FileExists(FileListBox1.FileName)) then Image1.Picture.LoadFromFile(FileListBox1.FileName);
end;

procedure TForm1.Zamknij1Click(Sender: TObject);
begin
Close;
end;

procedure TForm1.FormResize(Sender: TObject);
var wys :Integer;
begin
wys:=(Panel1.Height-Panel2.Height) div 2;
DirectoryListBox1.Height:=wys;
FileListBox1.Height:=wys;
end;

procedure TForm1.FileListBox1DblClick(Sender: TObject);
begin
//SystemParametersInfo(SPI_SETDESKWALLPAPER,0,PChar(FileListBox1.FileName),SPIF_UPDATEINIFILE or SPIF_SENDWININICHANGE); //Win32
SystemParametersInfo(SPI_SETDESKWALLPAPER,0,Marshal.StringToHGlobalUni(FileListBox1.FileName),SPIF_UPDATEINIFILE or SPIF_SENDWININICHANGE);
end;

end.
