unit Mainpage;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, jpeg, ExtCtrls, Buttons, ExtDlgs, IniFiles, ShlObj, ShellApi, Registry,
  Menus, ComCtrls, FileCtrl;

type
  TForm1 = class(TForm)
    Preview_BG: TImage;
    ICON_Preview: TImage;
    BG_Preview: TImage;
    ICON_TXT: TLabel;
    Image1: TImage;
    Label1: TLabel;
    Image2: TImage;
    Label2: TLabel;
    Label3: TLabel;
    Image3: TImage;
    Image4: TImage;
    Label4: TLabel;
    Label5: TLabel;
    GroupBox1: TGroupBox;
    GroupBox2: TGroupBox;
    Edit1: TEdit;
    SpeedButton1: TSpeedButton;
    Label6: TLabel;
    Label7: TLabel;
    Image5: TImage;
    Image6: TImage;
    Label9: TLabel;
    SpeedButton2: TSpeedButton;
    SpeedButton3: TSpeedButton;
    OpenPictureDialog1: TOpenPictureDialog;
    GroupBox3: TGroupBox;
    SpeedButton5: TSpeedButton;
    SpeedButton4: TSpeedButton;
    MainMenu1: TMainMenu;
    Datei1: TMenuItem;
    Optionen1: TMenuItem;
    Registry1: TMenuItem;
    Desktopinispeichern1: TMenuItem;
    Desktopinientfernen1: TMenuItem;
    N1: TMenuItem;
    Programmbeenden1: TMenuItem;
    Image7: TImage;
    Image8: TImage;
    Panel1: TPanel;
    SpeedButton6: TSpeedButton;
    SpeedButton7: TSpeedButton;
    Image9: TImage;
    Image10: TImage;
    Label8: TLabel;
    Label10: TLabel;
    Label11: TLabel;
    Label12: TLabel;
    Label13: TLabel;
    N2: TMenuItem;
    ber1: TMenuItem;
    Panel2: TPanel;
    Label14: TLabel;
    Label15: TLabel;
    Label16: TLabel;
    Label17: TLabel;
    Label18: TLabel;
    Label19: TLabel;
    Label20: TLabel;
    Label21: TLabel;
    Label22: TLabel;
    Label23: TLabel;
    Label24: TLabel;
    Label25: TLabel;
    Label26: TLabel;
    Image11: TImage;
    Image12: TImage;
    OK: TSpeedButton;
    Zielverzeichnisauswhlen1: TMenuItem;
    N3: TMenuItem;
    SpeedButton8: TSpeedButton;
    OpenPictureDialog2: TOpenDialog;
    GroupBox4: TGroupBox;
    Edit2: TEdit;
    Label27: TLabel;
    Label28: TLabel;
    Label29: TLabel;
    GroupBox5: TGroupBox;
    Label30: TLabel;
    SpeedButton9: TSpeedButton;
    Label31: TLabel;
    ColorDialog1: TColorDialog;
    Image13: TImage;
    Label32: TLabel;
    Label33: TLabel;
    ColorDialog2: TColorDialog;
    GroupBox6: TGroupBox;
    CheckBox1: TCheckBox;
    RadioButton1: TRadioButton;
    RadioButton2: TRadioButton;
    RadioButton3: TRadioButton;
    RecPanel: TPanel;
    ListBox1: TListBox;
    Label34: TLabel;
    ProgressBar1: TProgressBar;
    hierarchischentfernen1: TMenuItem;
    procedure hierarchischentfernen1Click(Sender: TObject);
    procedure unableimage1Click(Sender: TObject);
    procedure CheckBox1Click(Sender: TObject);
    procedure RadioButton3Click(Sender: TObject);
    procedure RadioButton2Click(Sender: TObject);
    procedure RadioButton1Click(Sender: TObject);
    procedure Label33Click(Sender: TObject);
    procedure SpeedButton9Click(Sender: TObject);
    procedure Label31Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure Label29Click(Sender: TObject);
    procedure Edit2Change(Sender: TObject);
    procedure Edit1DblClick(Sender: TObject);
    procedure SpeedButton8Click(Sender: TObject);
    procedure Label13Click(Sender: TObject);
    procedure Zielverzeichnisauswhlen1Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    procedure OKClick(Sender: TObject);
    procedure Image12Click(Sender: TObject);
    procedure Label23Click(Sender: TObject);
    procedure Label24Click(Sender: TObject);
    procedure Label21Click(Sender: TObject);
    procedure ber1Click(Sender: TObject);
    procedure Label11Click(Sender: TObject);
    procedure Label10Click(Sender: TObject);
    procedure Image7Click(Sender: TObject);
    procedure Image8Click(Sender: TObject);
    procedure SpeedButton7Click(Sender: TObject);
    procedure SpeedButton6Click(Sender: TObject);
    procedure Image8MouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure Image8MouseLeave(Sender: TObject);
    procedure Image8MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure Image8MouseEnter(Sender: TObject);
    procedure Image7MouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure Image7MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure Image7MouseLeave(Sender: TObject);
    procedure Image7MouseEnter(Sender: TObject);
    procedure Desktopinispeichern1Click(Sender: TObject);
    procedure Desktopinientfernen1Click(Sender: TObject);
    procedure Programmbeenden1Click(Sender: TObject);
    procedure Registry1Click(Sender: TObject);
    procedure RadioGroup1Click(Sender: TObject);
    procedure SpeedButton5Click(Sender: TObject);
    procedure SpeedButton1Click(Sender: TObject);
    procedure SpeedButton4Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure SpeedButton2Click(Sender: TObject);
    procedure SpeedButton3Click(Sender: TObject);
    procedure TileGraphic(const ATile: TBitmap; const ATarget: TCanvas);
    procedure SetDesktIniSubDirs(D_Path:String; Ergebnis: TStrings);
  procedure LoadDatas;
  procedure LadeVorlage(ID:Integer);
  procedure LoadIconDefault(aDestinationImage: TImage);
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
    procedure SetIconIndex(iNewIndex: Integer);
    procedure Setgoon(state: Boolean);
  end;

var
  Form1: TForm1;
  // Globale Variablen
  // Hintergrundbild, Iconfile, Zielverzeichnis, Farbwert
  s_NewBackground, s_NewIconFile, sUsedDirectory, ColStr: String;
  // Farbwert
  uColor: TColor;
  // Variable zum Suchen einer Vorlage
  vorlage: Integer = 0;
  // Aktuell ausgewählte Vorlage
  avorlage: Integer = 0;
  // IconIndex
  IconIndex: Integer = 0;
  //Pause während anderes Formoffen
  goon: Boolean = False;
implementation

uses symbloader;

{$R *.dfm}
{$R vorlagenbmps.res}
// Funktion: Messagebox   Quelle: http://www.Delphi-Treff.de
function ShowMessageDlgEx(const AText, ACaption: string; const ResID: Integer; Style: Cardinal = MB_OK):Cardinal;
var
 lpMsgBoxParams : MsgBoxParams;
begin
 with lpMsgBoxParams do
 begin
   cbSize              := SizeOf(lpMsgBoxParams);
   hwndOwner            := Application.Handle;
   hInstance            := SysInit.hInstance;
   lpszText            := PChar(AText);
   lpszCaption          := PChar(ACaption);
   dwStyle              := MB_USERICON or MB_TOPMOST or Style;
   lpszIcon            := MAKEINTRESOURCE(ResID);
   dwContextHelpID      := 0;
   lpfnMsgBoxCallback  := nil;
   dwLanguageId        := LANG_ENGLISH;
 end;

 Result := Cardinal(MessageBoxIndirect(lpMsgBoxParams));
end;

// Funktion: Letztes Zeichen einer Zeichenkette  Quelle: http://www.Delphi-Treff.de
function LastChar( const AString: String; const AChar: Char ): Integer;
var
  itor: Integer;
begin
  Result := -1;
  for itor := Length(AString)-1 downto 1 do
    if AString[itor] = AChar then
    begin
      Result := itor;
      break;
    end;
end;

function updateDesktopiniFiles(TList: TStrings; aRootDirectory: String):boolean;
var xCnt: Integer;
    tmpini,tini2: TIniFile;
begin
  //Funktion, um rekursiv Ordner zu erstellen
  Form1.Label34.Caption:='wird initialisiern....Bitte warten!';
  Form1.RecPanel.Visible:=True;
  Form1.ProgressBar1.Max:= TList.Count;
  Form1.ProgressBar1.Position:=0;
  tini2:= TIniFile.Create(aRootDirectory+'Desktop.ini');
  for xCnt := 0 to TList.Count - 1 do
    begin
    Form1.Label34.Caption:=MinimizeName(TList[xCnt],Form1.Label34.Canvas,200);
    Application.ProcessMessages();
    Form1.ProgressBar1.Position:=xCnt;
      if (FileExists(TList[xCnt]+'Desktop.ini')) then
      begin
          tmpini:= TIniFile.Create(TList[xCnt]+'Desktop.ini');
        try
          with tmpini do
          begin
            if not (ValueExists('.ShellClassInfo','IconFile')) then writeString('.ShellClassInfo','IconFile',tini2.ReadString('.ShellClassInfo','IconFile',''));
            if not (ValueExists('.ShellClassInfo','IconIndex')) then writeInteger('.ShellClassInfo','IconIndex',tini2.ReadInteger('.ShellClassInfo','IconIndex',0));
            if not (ValueExists('.ShellClassInfo','InfoTip')) then writeString('.ShellClassInfo','InfoTip',tini2.ReadString('.ShellClassInfo','InfoTip',''));
            if not (ValueExists('ExtShellFolderViews','Default')) then writeString('ExtShellFolderViews','Default','{BE098140-A513-11D0-A3A4-00C04FD706EC}');
            if not (ValueExists('{BE098140-A513-11D0-A3A4-00C04FD706EC}','IconArea_Image')) then writeString('{BE098140-A513-11D0-A3A4-00C04FD706EC}','IconArea_Image',tini2.ReadString('{BE098140-A513-11D0-A3A4-00C04FD706EC}','IconArea_Image',''));
            if not (ValueExists('{BE098140-A513-11D0-A3A4-00C04FD706EC}','Attributes')) then writeInteger('{BE098140-A513-11D0-A3A4-00C04FD706EC}','Attributes',tini2.ReadInteger('{BE098140-A513-11D0-A3A4-00C04FD706EC}','Attributes',0));
            if not (ValueExists('{BE098140-A513-11D0-A3A4-00C04FD706EC}','IconArea_Text')) then writeString('{BE098140-A513-11D0-A3A4-00C04FD706EC}','IconArea_Text',tini2.ReadString('{BE098140-A513-11D0-A3A4-00C04FD706EC}','IconArea_Text',''));
          end;
        finally
        tmpini.UpdateFile;
          tmpini.Free;
        end;
        SetFileAttributes(PChar(Copy( PChar(TList[xCnt] + 'Desktop.ini'), 1,LastChar(TList[xCnt] + 'Desktop.ini', '\')-1)), FILE_ATTRIBUTE_SYSTEM);
        SetFileAttributes(PChar(TList[xCnt] + 'Desktop.ini'),FILE_ATTRIBUTE_HIDDEN);
      end;
    end;
    tini2.Free;
    Form1.RecPanel.Visible:=False;
    ShowMessageDlgEx('rekursive Vererbung abgeschlossen','hierarchische Vererbung',101,mb_ok);
end;

function replaceDesktopiniFiles(TList: TStrings; aRootDirectory: String):boolean;
var xCnt: Integer;
    tmpini, tini2: TIniFile;
begin
  //Funktion, um rekursiv Ordner zu ersetzen
  Form1.Label34.Caption:='wird initialisiern....Bitte warten!';
  Form1.RecPanel.Visible:=True;
  Form1.ProgressBar1.Max:= TList.Count;
  Form1.ProgressBar1.Position:=0;
  tini2:= TIniFile.Create(aRootDirectory+'Desktop.ini');
  for xCnt := 0 to TList.Count - 1 do
    begin
    Form1.Label34.Caption:=MinimizeName(TList[xCnt],Form1.Label34.Canvas,200);
      Application.ProcessMessages();
      Form1.ProgressBar1.Position:=xCnt;
     tmpini:= TIniFile.Create(TList[xCnt]+'Desktop.ini');
        try
          with tmpini do
          begin
            writeString('.ShellClassInfo','IconFile',tini2.ReadString('.ShellClassInfo','IconFile',''));
            writeInteger('.ShellClassInfo','IconIndex',tini2.ReadInteger('.ShellClassInfo','IconIndex',0));
            writeString('.ShellClassInfo','InfoTip',tini2.ReadString('.ShellClassInfo','InfoTip',''));
            writeString('ExtShellFolderViews','Default','{BE098140-A513-11D0-A3A4-00C04FD706EC}');
            writeString('{BE098140-A513-11D0-A3A4-00C04FD706EC}','IconArea_Image',tini2.ReadString('{BE098140-A513-11D0-A3A4-00C04FD706EC}','IconArea_Image',''));
            writeInteger('{BE098140-A513-11D0-A3A4-00C04FD706EC}','Attributes',tini2.ReadInteger('{BE098140-A513-11D0-A3A4-00C04FD706EC}','Attributes',0));
            writeString('{BE098140-A513-11D0-A3A4-00C04FD706EC}','IconArea_Text',tini2.ReadString('{BE098140-A513-11D0-A3A4-00C04FD706EC}','IconArea_Text',''));
          end;
        finally
        tmpini.UpdateFile;
          tmpini.Free;
        end;
        SetFileAttributes(PChar(Copy( PChar(TList[xCnt] + 'Desktop.ini'), 1,LastChar(TList[xCnt] + 'Desktop.ini', '\')-1)), FILE_ATTRIBUTE_SYSTEM);
        SetFileAttributes(PChar(TList[xCnt] + 'Desktop.ini'),FILE_ATTRIBUTE_HIDDEN);
      end;
    Form1.RecPanel.Visible:=False;
    ShowMessageDlgEx('rekursive Vererbung abgeschlossen','hierarchische Vererbung',101,mb_ok);
end;

//Desktop.ini Files löschen
function DeleteDesktopIniFiles(aDir:String):Boolean;
begin
  if DeleteFile(aDir+'Desktop.ini') then
  ShowMessageDlgEx('Formatierung wurden entfernt.'+sLineBreak+'Es gelten nun wieder die Standardeinstellungen für das Verzeichnis!','Vorgang erfolgreich',101,mb_ok)
  else
  ShowMessageDlgEx('Formatierungen konnten nicht entfernt werden.'+sLineBreak+'Bitte versuchen Sie es nocheinmal!','Vorgang fehlgeschlagen',101,mb_ok)
end;

function createNewDesktopiniFiles(TList: TStrings; aRootDirectory: String):boolean;
var xCnt: Integer;
    tmpini,tini2: TIniFile;
begin
  //Funktion, um rekursiv Ordner zu erstellen
  Form1.Label34.Caption:='wird initialisiern....Bitte warten!';
  Form1.RecPanel.Visible:=True;
  Form1.ProgressBar1.Max:= TList.Count;
  Form1.ProgressBar1.Position:=0;
  tini2:= TIniFile.Create(aRootDirectory+'Desktop.ini');
  for xCnt := 0 to TList.Count - 1 do
    begin
    Form1.Label34.Caption:=MinimizeName(TList[xCnt],Form1.Label34.Canvas,200);
    Application.ProcessMessages();
    Form1.ProgressBar1.Position:=xCnt;
      if not (FileExists(TList[xCnt]+'Desktop.ini')) then
      begin
          tmpini:= TIniFile.Create(TList[xCnt]+'Desktop.ini');
        try
          with tmpini do
          begin
            writeString('.ShellClassInfo','IconFile',tini2.ReadString('.ShellClassInfo','IconFile',''));
            writeInteger('.ShellClassInfo','IconIndex',tini2.ReadInteger('.ShellClassInfo','IconIndex',0));
            writeString('.ShellClassInfo','InfoTip',tini2.ReadString('.ShellClassInfo','InfoTip',''));
            writeString('ExtShellFolderViews','Default','{BE098140-A513-11D0-A3A4-00C04FD706EC}');
            writeString('{BE098140-A513-11D0-A3A4-00C04FD706EC}','IconArea_Image',tini2.ReadString('{BE098140-A513-11D0-A3A4-00C04FD706EC}','IconArea_Image',''));
            writeInteger('{BE098140-A513-11D0-A3A4-00C04FD706EC}','Attributes',tini2.ReadInteger('{BE098140-A513-11D0-A3A4-00C04FD706EC}','Attributes',0));
            writeString('{BE098140-A513-11D0-A3A4-00C04FD706EC}','IconArea_Text',tini2.ReadString('{BE098140-A513-11D0-A3A4-00C04FD706EC}','IconArea_Text',''));
          end;
        finally
        tmpini.UpdateFile;
          tmpini.Free;
        end;
        SetFileAttributes(PChar(Copy( PChar(TList[xCnt] + 'Desktop.ini'), 1,LastChar(TList[xCnt] + 'Desktop.ini', '\')-1)), FILE_ATTRIBUTE_SYSTEM);
        SetFileAttributes(PChar(TList[xCnt] + 'Desktop.ini'),FILE_ATTRIBUTE_HIDDEN);
      end;
    end;
    tini2.Free;
    Form1.RecPanel.Visible:=False;
    ShowMessageDlgEx('rekursive Vererbung abgeschlossen','hierarchische Vererbung',101,mb_ok);
end;

//Funktion: Verzeichnis-Öffnen Dialog   Quelle: http://www.Delphi-Forum.de
function SelFolderB(Caption: string): String;
var
  bi: TBrowseInfo;
  lpBuffer: array[0..MAX_PATH+1] of Char;
  pidlPrograms, pidlBrowse: PItemIDList;
begin
  SHGetSpecialFolderLocation(GetActiveWindow, CSIDL_Desktop, pidlPrograms);

  with bi do begin
    hwndOwner := GetActiveWindow;
    pidlRoot := pidlPrograms;
    pszDisplayName := lpBuffer;
    lpszTitle := PChar(Caption);
    ulFlags := BIF_RETURNONLYFSDIRS;
    lpfn := nil;
    lParam := 0;
  end;

  pidlBrowse := SHBrowseForFolder(bi);
  if (pidlBrowse <> nil) then
    if SHGetPathFromIDList(pidlBrowse, lpBuffer) then Result := lpBuffer;
end;

// Funktion: Konvertierung JPEG --> BitMap  Quelle: http://www.Delphi-Treff.de
function JpegToBmp(const Filename: String):TBitMap;
var
 jpeg: TJPEGImage;
 bmp: TBitmap;
begin
 jpeg:=TJPEGImage.Create;
 try
   jpeg.LoadFromFile(Filename);
   bmp:=TBitmap.Create;
   try
     bmp.Assign(jpeg);
     Result:= bmp;
   finally
     //bmp.free;
   end;
 finally
   jpeg.free;
 end;
end;

// Prozedur: Bilder Wiederholen / kachel Quelle: http://www.Delphi-Treff.de
procedure TForm1.TileGraphic(const ATile: TBitmap; const ATarget: TCanvas);
var
 X, Y: Integer;
begin
 Y:=0;

 while Y < ATarget.ClipRect.Bottom  do
 begin
   X:=0;

   while X < ATarget.ClipRect.Right do
   begin
     ATarget.Draw(X, Y, ATile);
     Inc(X, ATile.Width);
   end;

   Inc(Y,ATile.Height);
 end;
end;

procedure TForm1.unableimage1Click(Sender: TObject);
begin

end;

//Funktion: Systemverzeichnis ermitteln   Quele: http://www.Delphi-Forum.de
function Systemverzeichnis:string;
var astring: Array[0..max_path+1] of Char;
begin
  GetSystemDirectory(astring, max_path+1);
  result := astring;
  if result[length(result)]<>'\' then
    result:=result+'\';
end;

//Prozedur: DefaultIcon aus Shell32.dll laden
procedure TForm1.LoadIconDefault(aDestinationImage: TImage);
var temIcon: TIcon;
begin
temIcon:= TIcon.Create;
try
 //Prüfen, ob System32-Verzeichnis mit shell32.dll vorhanden
  with temIcon do begin
    if FileExists(Systemverzeichnis+'shell32.dll') then begin
    //Laden des OrdnerIcons (IconIndex: 3);
    temIcon.Handle:= ExtractIcon(HInstance,PChar(Systemverzeichnis+'shell32.dll'),3);
    aDestinationImage.Picture.Icon:=temIcon;
    end else
    //Wenn vorhanden lade das Ordnersymbol aus Programmverzeichnis
    if FileExists(ExtractFilePath(ParamStr(0))+'folder.ico') then
      aDestinationImage.Picture.LoadFromFile(ExtractFilePath(ParamStr(0))+'folder.ico')
    else
      ShowMessageDlgEx('Es konnte kein Standardsymbol ermittelt werden.','Fehler',101,MB_OK);
  end;

finally
temIcon.free;
end;
end;

procedure TForm1.N2Click(Sender: TObject);
begin

end;

//Prozedur: Pause beenden
procedure TForm1.Setgoon(state: Boolean);
begin
goon:=state;
end;

//Prozedur: Zielverzeichnis wählen
procedure TForm1.Zielverzeichnisauswhlen1Click(Sender: TObject);
begin
SpeedButton1Click(Self);
end;

//Prozedur: IconIndex festlegen
procedure TForm1.SetIconIndex(iNewIndex: Integer);
begin
IconIndex:=iNewIndex;
end;

// Prozedur: Daten laden
procedure TForm1.LoadDatas;
var tmp: TIniFile;
bmp: TBitMap;
tmpicon:TIcon;
cs:String;
begin
//Prüfen, ob Desktop.ini existiert
if FileExists(Edit1.Text+'Desktop.ini') then
      begin
      //Desktop.ini laden
        tmp:= TIniFile.Create(Edit1.Text+'Desktop.ini');
        try
        //Prüfen, ob Textfarbe in Ini festgelegt ist
        if tmp.ValueExists('{BE098140-A513-11D0-A3A4-00C04FD706EC}','IconArea_Text') then begin
         ColStr:=tmp.ReadString('{BE098140-A513-11D0-A3A4-00C04FD706EC}','IconArea_Text','');
         //Farbwert analysieren
          cs:=ColStr[Length(ColStr)-5]+ColStr[Length(ColStr)-4]+ColStr[Length(ColStr)-3]+ColStr[Length(ColStr)-2]+ColStr[Length(ColStr)-1]+ColStr[Length(ColStr)];
          uColor := StrToInt('$' + Copy(cs, 1, 2) + Copy(cs, 3, 2) + Copy(cs, 5, 2));
        end else
        begin
        //sonst Standardfarbwert festsetzen
          uColor:=clBlack;
          ColStr:='';
        end;
        //Vorschau aktualisieren
 Label1.Font.Color:=uColor;
 Label2.Font.Color:=uColor;
 Label3.Font.Color:=uColor;
 Label4.Font.Color:=uColor;
 Label30.Font.Color:=uColor;
 //Prüfen, ob Hintergrundbild in Ini festgelegt ist
        if tmp.ValueExists('{BE098140-A513-11D0-A3A4-00C04FD706EC}','IconArea_Image') then
          s_NewBackground:=tmp.ReadString('{BE098140-A513-11D0-A3A4-00C04FD706EC}','IconArea_Image','');
 if FileExists(s_NewBackground) then begin
 //Wenn ja: Datei ggf. in BitMap wandeln und laden
              Bmp:=TBitmap.Create;
 try
   if (StrLower(PChar(ExtractFileExt(s_NewBackground)))='.bmp') then
   Bmp.LoadFromFile(s_NewBackground)
   else
   bmp:=JpegToBmp(s_NewBackground);
   //Vorschau kacheln und aktualisieren
   TileGraphic(Bmp, BG_Preview.Canvas);
 finally
 //Vorschau aktualisieren
 Image6.Picture.Bitmap:=BMP;
   Bmp.Free;
 end;
 end
 else
 begin
 //Standardhintergrund: leer (weiß)
   s_NewBackground:='';
   with BG_Preview.Canvas do begin
   Brush.Color:=clwhite;
   FillRect(Rect(0,0,BG_Preview.Width,BG_Preview.Height));
end;
with Image6.Canvas do begin
   Brush.Color:=clwhite;
   FillRect(Rect(0,0,Image6.Width,Image6.Height));
end;
 end;
 //Info-Tip laden
  if tmp.ValueExists('.ShellClassInfo','InfoTip') then begin
    Edit2.Text:=tmp.ReadString('.ShellClassInfo','InfoTip','');
  end
  else
  begin
   Edit2.Text:='created with Desktop.ini Maker 2';
  end;
  Edit2Change(Self);
 //Prüfen, ob Iconfile festgelegt in Ini
 if tmp.ValueExists('.ShellClassInfo','IconFile') then
          s_NewIconFile:=tmp.ReadString('.ShellClassInfo','IconFile','');
          if tmp.ValueExists('.ShellClassInfo','IconIndex') then
            IconIndex:=tmp.ReadInteger('.ShellClassInfo','IconIndex',0)
          else
            IconIndex:=0;

          s_NewIconFile:=StringReplace(s_NewIconFile,'%SystemRoot%\system32',Systemverzeichnis,[rfReplaceAll]);
          if FileExists(s_NewIconFile) then begin
          //Vorschau aktualisieren
           if strLower(PChar(ExtractFileExt(s_NewIconFile)))='.ico' then begin
            Image5.Picture.LoadFromFile(s_NewIconFile);
            ICON_Preview.Picture.LoadFromFile(s_NewIconFile);
           end else begin
            tmpicon:= TIcon.create;
            try
              tmpicon.handle:= ExtractIcon(HInstance,PChar(s_NewIconFile),IconIndex);
              Image5.Picture.Icon:= tmpIcon;
              ICON_Preview.Picture.Icon:= tmpIcon;
            finally
            tmpicon.free;
            end;
           end;
          end
          else
          begin
          //Standard: Folder.ico
          s_NewIconFile:='';
           LoadIconDefault(Image5);
           LoadIconDefault(ICON_Preview);
          end;
        finally
        tmp.free;
        end;
      end
      else
      // Standards laden, wenn keine Desktop.ini gefunden
      begin
      uColor:=clBlack;
          ColStr:='';
     s_NewBackground:='';
with BG_Preview.Canvas do begin
   Brush.Color:=clwhite;
   FillRect(Rect(0,0,BG_Preview.Picture.Width,BG_Preview.Picture.Height));
end;
with Image6.Canvas do begin
   Brush.Color:=clwhite;
   FillRect(Rect(0,0,image6.Picture.Width,image6.Picture.Height));
end;

   s_NewIconFile:='';
           LoadIconDefault(Image5);
           LoadIconDefault(ICON_Preview);
      end;
      sUsedDirectory:=Edit1.Text;

      if  (sUsedDirectory<>'') AND (DirectoryExists(sUsedDirectory)) then
      begin
        Label5.Font.Color:=ClBlack;
        Label5.Caption:=sUsedDirectory;
      end
      else
      begin
        if not (sUsedDirectory<>'') then
          Label5.Caption:='C:\Vorlage\'
        else
          Label5.Caption:=sUsedDirectory;
          Label5.Font.Color:=clRed;
      end;
end;

//Procedure: "Über..." schliessen
procedure TForm1.OKClick(Sender: TObject);
begin
Panel2.Hide;
end;

//Prozedur : Icon zurücksetzen auf Standard
procedure TForm1.Label10Click(Sender: TObject);
begin
case ShowMessageDlgEx('Wollen Sie das Ordnersymbol wirklich zurücksetzen?','Rücksetzen bestätigen',101,MB_YESNO) of
IDYES :
begin
s_NewIconFile:='';
LoadIconDefault(Image5);
LoadIconDefault(ICON_Preview);
end;
end;
end;

//Prozedur: Hintergrundbild zurücksetzen auf leer (weiß)
procedure TForm1.Label11Click(Sender: TObject);
begin
case ShowMessageDlgEx('Wollen Sie das Hintergrundbild wirklich zurücksetzen?','Rücksetzen bestätigen',101,MB_YESNO) of
IDYES :
begin
s_NewBackground:='';
Image6.Canvas.Brush.Color:=clWhite;
Image6.Canvas.FillRect(rect(0,0,image6.Picture.width,image6.Picture.height));
BG_Preview.Canvas.Brush.Color:=clWhite;
BG_Preview.Canvas.FillRect(rect(0,0,BG_Preview.Picture.width,BG_Preview.picture.height));
end;
end;
end;

procedure TForm1.Label13Click(Sender: TObject);
begin
ber1Click(Self);
end;

//PRozedur: Link öffnen
procedure TForm1.Label21Click(Sender: TObject);
begin
if ShellExecute(Application.Handle,
                 'open',
                 PChar('http://www.DaKirsche.eu'),
                 Nil, Nil, SW_NORMAL) <= 32 then
    ShowMessage('Es ist ein Fehler aufgetreten!');
end;

//PRozedur: Link öffnen
procedure TForm1.Label23Click(Sender: TObject);
begin
if ShellExecute(Application.Handle,
                 'open',
                 PChar('mailto:Support@DaKirsche-online.de'),
                 Nil, Nil, SW_NORMAL) <= 32 then
    ShowMessage('Es ist ein Fehler aufgetreten');
end;

//PRozedur: Link öffnen
procedure TForm1.Label24Click(Sender: TObject);
begin
if ShellExecute(Application.Handle,
                 'open',
                 PChar('http://www.opensource.org/licenses/gpl-license.php'),
                 Nil, Nil, SW_NORMAL) <= 32 then
    ShowMessage('Es ist ein Fehler aufgetreten');
end;

procedure TForm1.Label29Click(Sender: TObject);
begin
Edit2.Text:='';
Edit2Change(Self);
Edit2.SetFocus;
end;

procedure TForm1.Label31Click(Sender: TObject);
begin
uColor:=clBlack;
ColStr:='';
 Label1.Font.Color:=uColor;
 Label2.Font.Color:=uColor;
 Label3.Font.Color:=uColor;
 Label4.Font.Color:=uColor;
 Label30.Font.Color:=uColor;
end;

procedure TForm1.Label33Click(Sender: TObject);
var tbmp: TBitMap;
begin
if ColorDialog2.Execute then begin
if not FileExists(ExtractFilePath(ParamStr(0))+IntToHex(ColorToRgb(ColorDialog2.Color), 6)+'.bmp') then
begin
tbmp := TBitMap.Create();
try
tbmp.width:= 3;
tbmp.Height:= 3;
tbmp.Canvas.Pen.Color := ColorDialog2.Color;
tbmp.Canvas.Brush.Color := ColorDialog2.Color;
tbmp.Canvas.FillRect(rect(0,0,tbmp.width,tbmp.height));
finally
tbmp.SaveToFile(ExtractFilePath(ParamStr(0))+IntToHex(ColorToRgb(ColorDialog2.Color), 6)+'.bmp');
tbmp.free;
end;
end;
s_NewBackground:= ExtractFilePath(ParamStr(0))+IntToHex(ColorToRgb(ColorDialog2.Color), 6)+'.bmp';
image6.Picture.loadfromfile(ExtractFilePath(ParamStr(0))+IntToHex(ColorToRgb(ColorDialog2.Color), 6)+'.bmp');
tbmp := TBitMap.Create();
try
   if (StrLower(PChar(ExtractFileExt(s_NewBackground)))='.bmp') then
   tBmp.LoadFromFile(s_NewBackground)
   else
   tbmp:=JpegToBmp(s_NewBackground);

   TileGraphic(tBmp, BG_Preview.Canvas);
 finally
   tBmp.Free;
 end;
end;
end;

//Prozedur: Vorlage laden
procedure TForm1.LadeVorlage(ID:Integer);
var Path_s:String;
    tini: TIniFile;
    bmp: TBitMap;
    iconf: TIcon;
    cs:String;
begin
//Vorlagenpfad einlesen
  Path_s:= ExtractFilePath(ParamStr(0))+'Presents\Vorlagen\';

  //Auf vorhandene Vorlagen prüfen
    if FileExists(Path_s+IntToStr(ID)+'.dmv') then begin
      tini:=TIniFile.Create(Path_s+IntToStr(ID)+'.dmv');
  try
  //Vorlagenansicht aktualisieren
    s_NewIconFile:=tini.ReadString('Vorlage','Symbol','');
    IconIndex:=tini.ReadInteger('Vorlage','IconIndex',0);
    s_NewBackground:=tini.ReadString('Vorlage','BGPicture','');
    ColStr:=tini.ReadString('Vorlage','TextColor','');
    //Info-Tip laden
if tini.ValueExists('Vorlage','InfoTip') then begin
Edit2.Text:=tini.ReadString('Vorlage','InfoTip','');
Edit2Change(Self);
end
Else
begin
 Edit2.Text:='created with Desktop.ini Maker 2';
Edit2Change(Self);
end;
  finally
  tini.free;
  end;
    end;
    //Farbwert laden
 if ColStr<>'' then begin
    //Farbwert analysieren
          cs:=ColStr[Length(ColStr)-5]+ColStr[Length(ColStr)-4]+ColStr[Length(ColStr)-3]+ColStr[Length(ColStr)-2]+ColStr[Length(ColStr)-1]+ColStr[Length(ColStr)];
          uColor := StrToInt('$' + Copy(cs, 1, 2) + Copy(cs, 3, 2) + Copy(cs, 5, 2));
        end else
        begin
        //sonst Standardfarbwert festsetzen
          uColor:=clBlack;
          ColStr:='';
        end;

        // Hintergrundbild laden
   if (s_NewBackground<>'') AND (FileExists(s_NewBackground)) then begin
              Bmp:=TBitmap.Create;
 try
   if (StrLower(PChar(ExtractFileExt(s_NewBackground)))='.bmp') then
   Bmp.LoadFromFile(s_NewBackground)
   else
   bmp:=JpegToBmp(s_NewBackground);

   TileGraphic(Bmp, BG_Preview.Canvas);
 finally
 Image6.Picture.Bitmap:=BMP;
   Bmp.Free;
 end;
 end
 else
 begin
   s_NewBackground:='';
   with BG_Preview.Canvas do begin
   Brush.Color:=clwhite;
   FillRect(Rect(0,0,BG_Preview.Picture.Width,BG_Preview.Picture.Height));
end;
with Image6.Canvas do begin
   Brush.Color:=clwhite;
   FillRect(Rect(0,0,Image6.Picture.Width,Image6.Picture.Height));
end;
 end;
    //Vorlagensymbol laden
 if (s_NewIconFile<>'') AND (FileExists(s_NewIconFile)) then begin
 if StrLower(PChar(ExtractFileExt(s_NewIconFile)))='.ico' then begin
           Image5.Picture.LoadFromFile(s_NewIconFile);
           ICON_Preview.Picture.LoadFromFile(s_NewIconFile);
 end
 else
 begin
   iconf:= TIcon.Create;
   try
   iconf.Handle:= ExtractIcon(Handle, PChar(s_NEwIconFile), IconIndex);
   Image5.Picture.Icon:=iconf;
   ICON_Preview.Picture.Icon:=iconf;
   finally
   iconf.free;
   end;
 end;
          end
          else
          begin
          s_NewIconFile:='';
          LoadIconDefault(Image5);
          LoadIconDefault(ICON_Preview);
          end;

 Label1.Font.Color:=uColor;
 Label2.Font.Color:=uColor;
 Label3.Font.Color:=uColor;
 Label4.Font.Color:=uColor;
 Label30.Font.Color:=uColor;

end;
//Prozedur: Programm beenden
procedure TForm1.Programmbeenden1Click(Sender: TObject);
begin
Close;
end;

//Prozedur: Textfarbe einlesen
procedure TForm1.RadioButton1Click(Sender: TObject);
begin
RadioButton1.Checked:=True;
RadioButton2.Checked:=False;
RadioButton3.Checked:=False;
end;

procedure TForm1.RadioButton2Click(Sender: TObject);
begin
RadioButton2.Checked:=True;
RadioButton1.Checked:=False;
RadioButton3.Checked:=False;
end;

procedure TForm1.RadioButton3Click(Sender: TObject);
begin
RadioButton3.Checked:=True;
RadioButton2.Checked:=False;
RadioButton1.Checked:=False;
end;

procedure TForm1.RadioGroup1Click(Sender: TObject);
begin

end;

//Prozedur: Kontextmenüeintrag setzen/entfernen
procedure TForm1.Registry1Click(Sender: TObject);
var regist : TRegistry;
a : boolean;
begin
//setzt Schlüssel in Registry
  //create key in registry
 regist:=TRegistry.Create;
  try
    regist.RootKey:=HKEY_CLASSES_ROOT;
    a := regist.KeyExists('Directory\shell\desktop.ini\');
    if not a then begin
    regist.DeleteKey('Directory\shell\desktop.ini\');
    regist.OpenKey('Directory\shell\desktop.ini\',true);
    regist.WriteString('','starte Desktop.ini Maker');
    regist.OpenKey('Command',true);
    regist.WriteString('','"'+paramstr(0)+'"'+'"%1"');
    ShowMessage('Eintrag in die Registry erfolgreich.'+sLineBreak+'Sie haben nun bei Verzeichnissen ein neuen Kontextmenüeintrag "starte Destop.ini Maker".');
    end else begin
     regist.DeleteKey('Directory\shell\desktop.ini\');
     ShowMessage('Registryeintrag erfolgreich entfernt.');
    end;
     regist.RootKey:=HKEY_CLASSES_ROOT;
    a := regist.KeyExists('Directory\shell\desktop.ini\');
    if not a then begin
      Registry1.Caption:='Kontextmenü erweitern';
    end
    else
    begin
      Registry1.Caption:='Kontextmenüeintrag entfernen';
    end;
  finally
  regist.free;
 end;
end;

//Prozedur: "Über..." anzeigen
procedure TForm1.ber1Click(Sender: TObject);
begin
Panel2.top:=round((Form1.Height - Panel2.height)/2);
Panel2.left:=round((Form1.Width - Panel2.Width)/2);
Panel2.Show;
end;

//Prozedur: Löschen über Mainmenuestarten
procedure TForm1.CheckBox1Click(Sender: TObject);
begin
if CheckBox1.Checked then begin
  RadioButton1.Enabled:=True;
  RadioButton2.Enabled:=True;
  RadioButton3.Enabled:=True;
end
else
begin
  RadioButton1.Enabled:=False;
  RadioButton2.Enabled:=False;
  RadioButton3.Enabled:=False;
end;
end;

procedure TForm1.Desktopinientfernen1Click(Sender: TObject);
begin
SpeedButton5Click(Self);
end;

//Prozedur: Speichern über Mainmenuestarten
procedure TForm1.Desktopinispeichern1Click(Sender: TObject);
begin
SpeedButton4Click(Self);
end;

procedure TForm1.Edit1DblClick(Sender: TObject);
begin
if ShowMessageDlgEx('Die gewählte Aktion ist ungültig.'+sLineBreak+'Bitte verwenden Sie den Ordnerbrowser zum auswählen eines Zielverzeichnisses.'+sLineBreak+sLineBreak+'Wollen Sie jetzt den Ordnerbrowser starten?','ungültiger Vorgang',101,MB_YESNO)=IDYES then
 SpeedButton1Click(Self);
end;

procedure TForm1.Edit2Change(Sender: TObject);
begin
Label27.Caption:= 'noch '+(IntToStr(255 - (Length(PChar(Edit2.Text)))))+' Zeichen übrig';
ICON_Preview.Hint:=Edit2.Text;
end;

//Prozedur: Initialisierung
procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
var posini: TIniFile;
begin
// Config.ini erstellen, wenn Programm geschlossen wird
 posini:= TIniFile.Create(ExtractFilePath(ParamStr(0))+'config.ini');
 try
  with posini do begin
    WriteInteger('Main','pos_x',Form1.Left);
    WriteInteger('Main','pos_y',Form1.Top);
  end;
 finally
 posini.Free;
 end;
end;

procedure TForm1.FormCreate(Sender: TObject);
var regist : TRegistry;
a : boolean;
begin
//Prüft die Registry und setzt Caption
 regist:=TRegistry.Create;
  try
    regist.RootKey:=HKEY_CLASSES_ROOT;
    a := regist.KeyExists('Directory\shell\desktop.ini\');
    if not a then begin
      Registry1.Caption:='Kontextmenü erweitern';
    end
    else
    begin
      Registry1.Caption:='Kontextmenüeintrag entfernen';
    end;
  finally
  Regist.Free;
    end;
  //Übergebenes Verzeichnis einlesen und initialisieren
if ParamCount > 0 then
begin
  if DirectoryExists(ParamStr(1)) then begin
    Edit1.Text:=ParamStr(1);
    if Edit1.Text[Length(Edit1.Text)]<>'\' then
    Edit1.Text:=Edit1.Text+'\';
    LoadDatas;
  end;
end;
//Picturedialogs initialisieren
OpenPictureDialog1.InitialDir:=ExtractFilePath(ParamStr(0));
OpenPictureDialog2.InitialDir:=ExtractFilePath(ParamStr(0));

//Auf Vorlagendateien prüfen, ggf. laden
if FileExists(ExtractFilePath(ParamStr(0))+'Presents\Vorlagen\1.dmv') then
  begin
  avorlage:=0;
  Image8Click(Self);
  image8.Picture.Bitmap.Handle:=LoadBitMap(HInstance,'BMP4');
  end
  else
  begin
  //Sonst: "keine Vorlage" anzeigen
    LoadIconDefault(Image9);
    label8.Font.color:=clblack;
    Label8.Caption:='Keine Vorlage vorhanden';
  end;
  // Info-Tip initialisieren
  Edit2Change(Self);
  Form1.Width:=769;
  Form1.Height:=672;
end;

procedure TForm1.FormShow(Sender: TObject);
//Config.ini bei Programmstart laden
var posini: TIniFile;
    pos_x,pos_y: Integer;
begin
if FileExists(ExtractFilePath(ParamStr(0))+'config.ini') then begin
 posini:= TIniFile.Create(ExtractFilePath(ParamStr(0))+'config.ini');
 try
  with posini do begin
    pos_x:=ReadInteger('Main','pos_x',0);
    pos_y:=ReadInteger('Main','pos_y',0);
  end;
  if (pos_x >= screen.width - 50) OR (pos_y >= screen.Height - 50) then begin
    pos_x:=round((Screen.Width/2)-(Form1.Width/2)-10);
    pos_y:=round((Screen.Height/2)-(Form1.Height/2)-10);
  end;
 finally
 posini.Free;
 end;
end
else begin
  pos_x:=round((Screen.Width/2)-(Form1.Width/2)-10);
  pos_y:=round((Screen.Height/2)-(Form1.Height/2)-10);
end;

form1.Top:=pos_y;
form1.Left:=pos_x;
with image13.Canvas do begin
  brush.color:=clblack;
  pen.color:=clblack;
  fillrect(rect(0,0,image13.Width,image13.height));
end;
end;

procedure TForm1.hierarchischentfernen1Click(Sender: TObject);
var Ergebnis: TStrings;
    xCnt: Integer;
begin
Listbox1.Clear;
Ergebnis:= TStrings.Create();
if FileExists(Edit1.Text+'Desktop.ini') then begin
if ShowMessageDlgEx('Wollen Sie die Formatierung aller Ordner, einschliesslich der Untereordner wirklich entfernen?','Löschen bestätigen',101,MB_YESNO)=IDYES then
begin
SetDesktIniSubDirs(Edit1.Text,Ergebnis);
if not (SetFileAttributes(PChar(Copy( PChar(sUsedDirectory + 'Desktop.ini'), 1,LastChar(sUsedDirectory + 'Desktop.ini', '\')-1)), FILE_ATTRIBUTE_NORMAL)) then
ShowMessageDlgEx('Attribute konnten nicht zurückgesetzt werden.'+sLineBreak+'Bitte überprüfen Sie das Verzeichnis und ändern Sie es manuell!','Attributänderung fehlgeschlagen',101,mb_ok);
   DeleteFile(sUsedDirectory+'Desktop.ini');
   if (ListBox1.Items.Count > 0) then
   begin
      for xCnt := 0 to Listbox1.items.Count - 1 do
        begin
          if FileExists(Listbox1.Items[xCnt]+'Desktop.ini') then
          begin
            SetFileAttributes(PChar(Copy( PChar(Listbox1.Items[xCnt] + 'Desktop.ini'), 1,LastChar(Listbox1.Items[xCnt] + 'Desktop.ini', '\')-1)), FILE_ATTRIBUTE_NORMAL);
            DeleteFile(Listbox1.Items[xCnt]+'Desktop.ini');
          end;
        end;
   end;
   ShowMessageDlgEx('Alle Formatierungen wurden erfolgreich entfernt!'+sLineBreak+'Sowohl für Haupt- als auch für Unterverzeichnisse gelten nun wieder die Standardeinstellungen!','Formatierung aufgehoben!',101,mb_yesno);
  end
else
  ShowMessageDlgEx('Es wurde keine Formatierung gefunden.'+sLineBreak+'Bitte überprüfen Sie das Verzeichnis und versuchen Sie es erneut!','Vorgang fehlgeschlagen',101,mb_ok);
  LoadDatas;
end;
end;

//Prozedur: Link öffnen
procedure TForm1.Image12Click(Sender: TObject);
begin
if ShellExecute(Application.Handle,
                 'open',
                 PChar('http://www.DaKirsche.eu'),
                 Nil, Nil, SW_NORMAL) <= 32 then
    ShowMessage('Es ist ein Fehler aufgetreten!');
end;

//Prozedur: vorige Vorlage anzeigen
procedure TForm1.Image7Click(Sender: TObject);
var Path_s, ColStrt,icont,bgt: String;
    tini: TIniFile;
    ID,iconi:Integer;
    uColort: TColor;
    iconf: TIcon;
    cs:String;
begin
Path_s:= ExtractFilePath(ParamStr(0))+'Presents\Vorlagen\';
ID:= avorlage - 1;
     //Wenn Vorlage existiert laden in Vorlagenansicht
    if FileExists(Path_s+IntToStr(ID)+'.dmv') then begin
      tini:=TIniFile.Create(Path_s+IntToStr(ID)+'.dmv');
  try
  avorlage:=ID;
  bgt:=tini.ReadString('Vorlage','BGPicture','');
  icont:=tini.ReadString('Vorlage','Symbol','');
  iconi:=tini.ReadInteger('Vorlage','IconIndex',0);

    if fileexists(icont) then
    begin
    if StrLower(PChar(ExtractFileExt(icont)))='.ico' then
    image9.Picture.LoadFromFile(icont)
    else
    begin
      iconf:= TIcon.Create;
      try
     iconf.Handle:= ExtractIcon(Handle, PChar(icont), iconi);
     Image9.Picture.Icon := iconf;
    finally
     iconf.free;
    end;
    end;
    end
     else LoadIconDefault(Image9);
    if FileExists(bgt) then begin
     image10.Picture.LoadFromFile(bgt);
     image10.Show;
     end else begin
      image10.Hide;
    end;
    ColStrt:=tini.ReadString('Vorlage','TextColor','');
    uColort:=clBlack;
     if ColStrt<>'' then begin
    //Farbwert analysieren
          cs:=ColStrt[Length(ColStrt)-5]+ColStrt[Length(ColStrt)-4]+ColStrt[Length(ColStrt)-3]+ColStrt[Length(ColStrt)-2]+ColStrt[Length(ColStrt)-1]+ColStrt[Length(ColStrt)];
          uColort := StrToInt('$' + Copy(cs, 1, 2) + Copy(cs, 3, 2) + Copy(cs, 5, 2));
        end else
        begin
        //sonst Standardfarbwert festsetzen
          uColort:=clBlack;
          ColStrt:='';
        end;
    label8.Font.Color:=uColort;
    Label8.Caption:='Vorlage Nr. '+inttostr(avorlage);
  finally
  tini.free;
  end;
end;
if FileExists(Path_s+IntToStr(avorlage-1)+'.dmv') then
      Image7.Picture.Bitmap.Handle:=LoadBitmap(HInstance,'BMP2')
else Image7.Picture.Bitmap.Handle:=LoadBitmap(HInstance,'BMP1');
end;

// Prozeduren: Grafische Änderung der Vorlagennavigation "zurück"
procedure TForm1.Image7MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
var ID: Integer;
    Path_s: String;
begin
Path_s:= ExtractFilePath(ParamStr(0))+'Presents\Vorlagen\';
ID:= avorlage - 1;
if FileExists(Path_s+IntToStr(ID)+'.dmv') then begin
Image7.Picture.Bitmap.Handle:=LoadBitmap(HInstance,'BMP3');
end;
end;

procedure TForm1.Image7MouseEnter(Sender: TObject);
var ID: Integer;
    Path_s: String;
begin
Path_s:= ExtractFilePath(ParamStr(0))+'Presents\Vorlagen\';
ID:= avorlage - 1;
if FileExists(Path_s+IntToStr(ID)+'.dmv') then begin
  Image7.Picture.Bitmap.Handle:=LoadBitmap(HInstance,'BMP2');
end;
end;

procedure TForm1.Image7MouseLeave(Sender: TObject);
begin
Image7.Picture.Bitmap.Handle:=LoadBitmap(HInstance,'BMP1');
end;

procedure TForm1.Image7MouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
var ID: Integer;
    Path_s: String;
begin
Path_s:= ExtractFilePath(ParamStr(0))+'Presents\Vorlagen\';
ID:= avorlage - 1;
if FileExists(Path_s+IntToStr(ID)+'.dmv') then begin
Image7.Picture.Bitmap.Handle:=LoadBitmap(HInstance,'BMP2');
end else
Image7.Picture.Bitmap.Handle:=LoadBitmap(HInstance,'BMP1');
end;

//Prozedur: Nächste Vorlage laden, falls vorhanden
procedure TForm1.Image8Click(Sender: TObject);
var Path_s, ColStrt,icont,bgt: String;
    tini: TIniFile;
    ID, iconi:Integer;
    uColort: TColor;
    iconf: TIcon;
    cs:String;
begin
Path_s:= ExtractFilePath(ParamStr(0))+'Presents\Vorlagen\';
ID:= avorlage + 1;
    if FileExists(Path_s+IntToStr(ID)+'.dmv') then begin
      tini:=TIniFile.Create(Path_s+IntToStr(ID)+'.dmv');
  try
  avorlage:=ID;
  bgt:=tini.ReadString('Vorlage','BGPicture','');
  icont:=tini.ReadString('Vorlage','Symbol','');
     iconi:=tini.ReadInteger('Vorlage','IconIndex',0);

    if fileexists(icont) then
    begin
    if StrLower(PChar(ExtractFileExt(icont)))='.ico' then
    image9.Picture.LoadFromFile(icont)
    else
    begin
      iconf:= TIcon.Create;
      try
     iconf.Handle:= ExtractIcon(Handle, PChar(icont), iconi);
     Image9.Picture.Icon := iconf;
    finally
     iconf.free;
    end;
    end;
    end else LoadIconDefault(Image9);
    if FileExists(bgt) then begin
     image10.Picture.LoadFromFile(bgt);
     image10.Show;
     end else begin
      image10.Hide;
    end;
    ColStrt:=tini.ReadString('Vorlage','TextColor','');
    uColort:=clBlack;
     if ColStrt<>'' then begin
    //Farbwert analysieren
          cs:=ColStrt[Length(ColStrt)-5]+ColStrt[Length(ColStrt)-4]+ColStrt[Length(ColStrt)-3]+ColStrt[Length(ColStrt)-2]+ColStrt[Length(ColStrt)-1]+ColStrt[Length(ColStrt)];
          uColort := StrToInt('$' + Copy(cs, 1, 2) + Copy(cs, 3, 2) + Copy(cs, 5, 2));
        end else
        begin
        //sonst Standardfarbwert festsetzen
          uColort:=clBlack;
          ColStrt:='';
        end;
    label8.Font.Color:=uColort;
    Label8.Caption:='Vorlage Nr. '+inttostr(avorlage);
  finally
  tini.free;
  end;
end;
if FileExists(Path_s+IntToStr(avorlage+1)+'.dmv') then
      Image8.Picture.Bitmap.Handle:=LoadBitmap(HInstance,'BMP5')
else Image8.Picture.Bitmap.Handle:=LoadBitmap(HInstance,'BMP4');
end;

//Prozeduren: Grafische Änderung der Navigation "Nächste Vorlage"
procedure TForm1.Image8MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
var ID: Integer;
    Path_s: String;
begin
Path_s:= ExtractFilePath(ParamStr(0))+'Presents\Vorlagen\';
ID:= avorlage + 1;
if FileExists(Path_s+IntToStr(ID)+'.dmv') then begin
Image8.Picture.Bitmap.Handle:=LoadBitmap(HInstance,'BMP6');
end;
end;

procedure TForm1.Image8MouseEnter(Sender: TObject);
var ID: Integer;
    Path_s: String;
begin
Path_s:= ExtractFilePath(ParamStr(0))+'Presents\Vorlagen\';
ID:= avorlage + 1;
if FileExists(Path_s+IntToStr(ID)+'.dmv') then begin
Image8.Picture.Bitmap.Handle:=LoadBitmap(HInstance,'BMP5');
end;
end;

procedure TForm1.Image8MouseLeave(Sender: TObject);
begin
Image8.Picture.Bitmap.Handle:=LoadBitmap(HInstance,'BMP4');
end;

procedure TForm1.Image8MouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
var ID: Integer;
    Path_s: String;
begin
Path_s:= ExtractFilePath(ParamStr(0))+'Presents\Vorlagen\';
ID:= avorlage + 1;
if FileExists(Path_s+IntToStr(ID)+'.dmv') then begin
Image8.Picture.Bitmap.Handle:=LoadBitmap(HInstance,'BMP5');
end else
Image8.Picture.Bitmap.Handle:=LoadBitmap(HInstance,'BMP4');
end;

//Prozedur: Zielverzeichnis wählen
procedure TForm1.SpeedButton1Click(Sender: TObject);
var
  S: String;
begin
//Ordner-wählen-Dialog öffnen
  S := SelFolderB('Bitte Zielverzeichnis wählen');
  //Wenn Existent, dann auf Backslash am Ende prüfen und initialisierenin sUsedDirectory
  if DirectoryExists(S) then begin
    sUsedDirectory:=S;
if sUsedDirectory[Length(sUsedDirectory)]<>'\' then
  sUsedDirectory:=sUsedDirectory+'\';
  Edit1.Text:=sUsedDirectory;
   LoadDatas;
  end
  else
  begin
   sUsedDirectory:='';
  Edit1.Text:=sUsedDirectory;
  end;
end;

//Prozedur: Iconfile auswählen/laden
procedure TForm1.SpeedButton2Click(Sender: TObject);
var icon: TIcon;
    tini: TINIFILE;
begin
tini:= TINIFILE.Create(ExtractFilePath(ParamStr(0))+'\config.ini');
   try
   OpenPictureDialog2.InitialDir:=tini.ReadString('Paths','IconFolder','');
   finally
   tini.free;
   end;
if OpenPictureDialog2.Execute then begin
if (OpenPictureDialog2.FileName<>'') AND FileExists(OpenPictureDialog2.FileName) then
  begin
  if (StrLower(PChar(ExtractFileExt(OpenPictureDialog2.Filename)))='.ico') then
  begin
   tini:= TINIFILE.Create(ExtractFilePath(ParamStr(0))+'\config.ini');
   try
   tini.WriteString('Paths','IconFolder',ExtractFilePath(OpenPictureDialog2.Filename));
   finally
   tini.free;
   end;
  //Dateien vom Typ .ico
    s_NewIconFile:=OpenPictureDialog2.FileName;
    Image5.Picture.LoadFromFile(s_NewIconFile);
    ICON_Preview.Picture.LoadFromFile(s_NewIconFile);
    IconIndex:=0;
  end
  else
  begin
    //Dateien vom Typ .dll und .exe
    icon:= TIcon.Create;
    s_NewIconFile:=OpenPictureDialog2.FileName;
    goon:=False;
    symbolloader.LoadIcons(OpenPictureDialog2.Filename);
    //Pause, solange Auswahlfenster geöffnet ist
    while not goon do begin
    Application.Processmessages;
    end;
    //danach Information auswerten und verwenden
    try
    if IconIndex>-1 then begin

     icon.Handle:= ExtractIcon(Handle, PChar(s_NewIconFile), IconIndex);
     Image5.Picture.Icon := icon;
     ICON_Preview.Picture.Icon:= icon;
    end
    else
    begin
      LoadIconDefault(Image5);
      LoadIconDefault(ICON_Preview);
    end;
    finally
     icon.free;
    end;
  end;
  end
else
begin
  LoadIconDefault(Image5);
  LoadIconDefault(ICON_Preview);
end;
end;
end;

//Prozedur: Hintergrundbild auswählen/laden
procedure TForm1.SpeedButton3Click(Sender: TObject);
var BMP:TBitMap;
    tini: TINIFILE;
begin
tini:= TINIFILE.Create(ExtractFilePath(ParamStr(0))+'\config.ini');
   try
   OpenPictureDialog1.InitialDir:=tini.ReadString('Paths','BGFolder','');
   finally
   tini.free;
   end;
if OpenPictureDialog1.Execute then begin
if (OpenPictureDialog1.FileName<>'') AND FileExists(OpenPictureDialog1.FileName) then
begin
  tini:= TINIFILE.Create(ExtractFilePath(ParamStr(0))+'\config.ini');
   try
   tini.WriteString('Paths','BGFolder',ExtractFilePath(OpenPictureDialog1.Filename));
   finally
   tini.free;
   end;
  s_NewBackground:=OpenPictureDialog1.Filename;
  Bmp:=TBitmap.Create;
 try
   if (StrLower(PChar(ExtractFileExt(s_NewBackground)))='.bmp') then
   Bmp.LoadFromFile(s_NewBackground)
   else
   bmp:=JpegToBmp(s_NewBackground);

   TileGraphic(Bmp, BG_Preview.Canvas);
 finally
 Image6.Picture.Bitmap:=BMP;
   Bmp.Free;
 end;
end
else begin
  Image6.Picture.Free;
  BG_Preview.Picture.Free;
  s_NewBackground:='';
end;
end;
end;

//Prozedur: Desktop.ini anlegen --> Änderungen speichern
procedure TForm1.SpeedButton4Click(Sender: TObject);
var
  tmpINI: TIniFile;
  Ergebnis: TStrings;
begin
if DirectoryExists(sUsedDirectory) then begin

tmpINI:= TIniFile.Create(sUsedDirectory+'Desktop.ini');
try
  with tmpINI do begin
    if s_NewIconFile<>'' then begin
      WriteString('.ShellClassInfo','IconFile',s_NewIconFile);
      WriteInteger('.ShellClassInfo','IconIndex',IconIndex);
    end;
    if Edit2.Text<>'' then
      WriteString('.ShellClassInfo','InfoTip',Edit2.Text);

    //WriteInteger('.ShellClassInfo','ConfirmFileOp',0);
    WriteString('ExtShellFolderViews','Default','{BE098140-A513-11D0-A3A4-00C04FD706EC}');
    if s_NewBackground<>'' then begin
      WriteString('{BE098140-A513-11D0-A3A4-00C04FD706EC}','IconArea_Image',s_NewBackground);
    end;
    WriteInteger('{BE098140-A513-11D0-A3A4-00C04FD706EC}','Attributes',1);
    if ColStr<>'' then
      WriteString('{BE098140-A513-11D0-A3A4-00C04FD706EC}','IconArea_Text',ColStr);
  end;
finally
tmpINI.UpdateFile;
//SetFileAttributes(PChar(sUsedDirectory + 'Desktop.ini'), FILE_ATTRIBUTE_SYSTEM);
    if Length(PChar(Edit1.text + 'Desktop.ini')) > 3 then
    begin
      SetFileAttributes(PChar(Copy( PChar(sUsedDirectory + 'Desktop.ini'), 1,LastChar(sUsedDirectory + 'Desktop.ini', '\')-1)), FILE_ATTRIBUTE_SYSTEM);
  end;
  tmpINI.Free;
  SetFileAttributes(PChar(sUsedDirectory + 'Desktop.ini'),FILE_ATTRIBUTE_HIDDEN);

end;
if FileExists(sUsedDirectory+'Desktop.ini') then begin
  ShowMessageDlgEx('Der Speichervorgang war erfolgreich!','Speichern erfolgreich',101,MB_OK);
  //hierarchisches Verhalten abarbeiten
if (CheckBox1.Checked) then
begin
 if ShowMessageDlgEx('Sind Sie sicher, dass Sie die vorgenommenen Einstellungen auf alle Unterordner übernehmen wollen? Dies kann u.U. einige Zeit dauern!','hierarchische Vererbung der Desktop.ini Einstellungen',101,MB_YESNO)=IDYES then
 begin
   ListBox1.Clear;
   Ergebnis:= TStrings.Create();
   SetDesktIniSubDirs(sUsedDirectory,Ergebnis);
   if (ListBox1.Items.Count > 0) then
   begin
    if RadioButton1.Checked then updateDesktopiniFiles(ListBox1.Items,sUsedDirectory)
    else if RadioButton2.Checked then replaceDesktopiniFiles(ListBox1.Items,sUsedDirectory)
    else if RadioButton3.Checked then createNewDesktopiniFiles(ListBox1.Items,sUsedDirectory)
   end
   else
    ShowMessageDlgEx('Es wurden keine Unterverzeichnisse gefunden. Bitte führen Sie den Vorgang erneut aus!','hierarchische Vererbung',101,mb_ok);
 end else
   ShowMessageDlgEx('Die hierarchische Vererbung wurde abgebrochen!','hierarchische Vererbung abgebrochen!',101,mb_OK);
end;
 end
else
  ShowMessageDlgEx('Speichern war leider nicht erfolgreich!'+sLineBreak+'Bitte versuchen Sie es noch einmal!','Speichern fehlgeschlagen',101,MB_OK);
end
else
ShowMessageDlgEx('Das angegebene Verzeichnis existiert nicht!','ungültiges Verzeichnis',101,mb_ok);
end;

//Prozedur: Desktop.ini löschen --> Vorschau aktualisieren
procedure TForm1.SpeedButton5Click(Sender: TObject);
begin
    if FileExists(Form1.Edit1.Text+'Desktop.ini') then begin
if ShowMessageDlgEx('Wollen Sie die Formatierung wirklich entfernen?','Löschen bestätigen',101,MB_YESNO)=IDYES then
begin
if not (SetFileAttributes(PChar(Copy( PChar(sUsedDirectory + 'Desktop.ini'), 1,LastChar(sUsedDirectory + 'Desktop.ini', '\')-1)), FILE_ATTRIBUTE_NORMAL)) then
ShowMessageDlgEx('Attribute konnten nicht zurückgesetzt werden.'+sLineBreak+'Bitte überprüfen Sie das Verzeichnis und ändern Sie es manuell!','Attributänderung fehlgeschlagen',101,mb_ok);
   DeleteDesktopiniFiles(sUsedDirectory);
end;
  end
else
  ShowMessageDlgEx('Es wurde keine Formatierung gefunden.'+sLineBreak+'Bitte überprüfen Sie das Verzeichnis und versuchen Sie es erneut!','Vorgang fehlgeschlagen',101,mb_ok);
  LoadDatas
end;

//Prozedur: Als neue Vorlage speichern
procedure TForm1.SpeedButton6Click(Sender: TObject);
var Path_s:String;
    v: boolean;
    tini: TIniFile;
begin
//Abfrage: wirklich speichern?
case ShowMessageDlgEx('Wollen Sie die aktuelle Zusammenstellung als Vorlage speichern?','Speichern bestätigen',101,MB_YESNO) of
IDYES :
begin
  v:=True;
  vorlage:=0;
  Path_s:= ExtractFilePath(ParamStr(0))+'Presents\Vorlagen\';
  while v do begin
    vorlage:=vorlage + 1;
    if FileExists(Path_s+IntToStr(vorlage)+'.dmv') then
      v:=True
    else
      v:=False;
  end;
  tini:=TIniFile.Create(Path_s+IntToStr(vorlage)+'.dmv');
  try
    tini.WriteString('Vorlage','Symbol',s_NewIconFile);
    tini.WriteInteger('Vorlage','IconIndex',IconIndex);
    tini.WriteString('Vorlage','BGPicture',s_NewBackground);
    tini.WriteString('Vorlage','TextColor',ColStr);
    tini.WriteString('Vorlage','InfoTip',Edit2.Text);
  finally
  avorlage:=vorlage - 1;
  ShowMessageDlgEx('Vorlage gespeichert als "Vorlage Nr. '+IntToStr(vorlage)+'"!','Vorlage gespeichert',101,mb_OK);
  Image8Click(Sender);
  LadeVorlage(avorlage);
  tini.free;
  end;
end;
IDNO :
ShowMessageDlgEx('Speichervorgang abgebrochen!','Vorgang abgebrochen',101,MB_OK);
end;
end;

//Prozedur: Aktuelle Vorlage in Ansicht laden
procedure TForm1.SpeedButton7Click(Sender: TObject);
begin
LadeVorlage(avorlage);
end;

procedure TForm1.SpeedButton8Click(Sender: TObject);
var a: Integer;
begin
if (FileExists(ExtractFilePath(ParamStr(0))+'Presents\Vorlagen\'+inttostr(avorlage)+'.dmv')) then begin
  case ShowMessageDlgEx('Wollen Sie diese Vorlage wirklich unwiederruflich löschen?','Löschen bestätigen',101,mb_yesno) of
  IDYES : begin
    //Vorlage löschen...folgende Vorlagen umbenennen
    if DeleteFile(ExtractFilePath(ParamStr(0))+'Presents\Vorlagen\'+inttostr(avorlage)+'.dmv') then begin
    a:= avorlage;
    while (FileExists(ExtractFilePath(ParamStr(0))+'Presents\Vorlagen\'+inttostr(a+1)+'.dmv')) do begin
      RenameFile(ExtractFilePath(ParamStr(0))+'Presents\Vorlagen\'+inttostr(a+1)+'.dmv',ExtractFilePath(ParamStr(0))+'Presents\Vorlagen\'+inttostr(a)+'.dmv');
    Inc(a,1);
    end;
    end;
  end;
  end;
end;

//Auf Vorlagendateien prüfen, ggf. laden
if FileExists(ExtractFilePath(ParamStr(0))+'Presents\Vorlagen\1.dmv') then
  begin
  avorlage:=0;
  Image8Click(Self);
  image8.Picture.Bitmap.Handle:=LoadBitMap(HInstance,'BMP4');
  end
  else
  begin
  //Sonst: "keine Vorlage" anzeigen
  avorlage:=0;
    LoadIconDefault(Image9);
    Image10.Hide;
    label8.Font.color:=clblack;
    Label8.Caption:='Keine Vorlage vorhanden';
  end;
end;

procedure TForm1.SpeedButton9Click(Sender: TObject);
begin
if ColorDialog1.Execute then begin
uColor:=ColorDialog1.Color;
 ColStr := IntToHex(ColorToRgb(uColor), 6);
 ColStr := '0x00' + Copy(ColStr, 1, 2) + Copy(ColStr, 3, 2) + Copy(ColStr, 5, 2);

end else begin
uColor:=clBlack;
ColStr:='';
end;
 Label1.Font.Color:=uColor;
 Label2.Font.Color:=uColor;
 Label3.Font.Color:=uColor;
 Label4.Font.Color:=uColor;
 Label30.Font.Color:=uColor;
end;

procedure TForm1.SetDesktIniSubDirs(D_Path: string; Ergebnis: TStrings);
var sr: TSearchRec;
begin
    if FindFirst(D_Path + '*.*', faDirectory+faSysFile, SR) = 0 then try
      repeat
        if ((SR.attr and faDirectory+faSysFile) = (faDirectory+faSysFile)) and
           (SR.Name <> '.') and (SR.Name <> '..') then begin
              SetDesktIniSubDirs(D_Path + SR.Name + '\', Ergebnis);
              Listbox1.Items.Add(D_Path + SR.name+'\');
           end;
      until FindNext(SR) <> 0;
    finally
      FindClose(SR);
    end;  
end;

end.
