home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 December / Chip_2001-12_cd1.bin / zkuste / delphi / kompon / d3456 / LSPICEDT.ZIP / D3 / LsPicEditorMainD3.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2001-09-05  |  36.1 KB  |  1,306 lines

  1. {*****************************************************************************
  2.  Component   :  LsPicEditorMainD5.pas is a part of the LsPictureEditor
  3.                 (a Picture and Bitmap property editor for Delphi).
  4.                 Refrring to LsPictureEditor.txt for more infomation.
  5.  
  6.  Version     :  2.300 for Delphi versions 3, 4 & 5.
  7.                 (Last Modified September 2001)
  8.  
  9.  Author      :  Leo D. Shih  e-mail: <ldshih@ecn.ab.ca>
  10.  
  11.  Copyright   :  (C)1998-2001 by Leo D. Shih, all rights reserved.
  12.  
  13.  DISCLAIMER  :  Current version of TLsPictureEditor (Software) is distributed
  14.                 as freeware, without warranties of any kind. either expressed
  15.                 or implied.  In no event shall the author be liable for any
  16.                 problems or damages that may result from the use of this
  17.                 software.
  18.  
  19. *****************************************************************************}
  20.  
  21. {$IFNDEF VER90} //If not D2
  22.   {$DEFINE D3_OR_hIGHER}
  23.   {$IFNDEF VER100} //If not D3
  24.     {$DEFINE D4_OR_HIGHER}
  25.     {$IFNDEF VER120} //If not D4
  26.       {DEFINE D5_OR_HIGHER}
  27.     {$ENDIF}
  28.   {$ENDIF}
  29. {$ENDIF}
  30.  
  31. unit LsPicEditorMainD3;
  32.  
  33. interface
  34.  
  35. uses
  36.   Windows, Classes, Graphics, Forms, Controls, FileCtrl, StdCtrls,
  37.   ExtCtrls, Buttons, Dialogs, Menus, Clipbrd, ComCtrls, SysUtils,
  38.   IniFiles, Spin, ShellAPI, ShlObj
  39. {$IFDEF D4_OR_HIGHER},
  40.   ImgList, ToolWin
  41. {$ENDIF};
  42.  
  43.  
  44. type
  45.   TPEMainForm = class(TForm)
  46.     SaveDialog1: TSaveDialog;
  47.     PopupMenu1: TPopupMenu;
  48.     NumGlyph1: TMenuItem;
  49.     N1: TMenuItem;
  50.     CopyImage1: TMenuItem;
  51.     SaveImage1: TMenuItem;
  52.     LbxBookMark: TListBox;
  53.     StatusBar1: TStatusBar;
  54.     PageControl1: TPageControl;
  55.     TabSheet1: TTabSheet;
  56.     TabSheet2: TTabSheet;
  57.     TabSheet3: TTabSheet;
  58.     TabSheet4: TTabSheet;
  59.     StretchCheck: TCheckBox;
  60.     Image1: TImage;
  61.     Image2: TImage;
  62.     Image3: TImage;
  63.     Image4: TImage;
  64.     Panel1: TPanel;
  65.     Panel2: TPanel;
  66.     Panel3: TPanel;
  67.     Panel4: TPanel;
  68.     Panel5: TPanel;
  69.     Panel6: TPanel;
  70.     Panel7: TPanel;
  71.     Panel8: TPanel;
  72.     Panel9: TPanel;
  73.     Panel10: TPanel;
  74.     SpeedButton1: TSpeedButton;
  75.     SpeedButton2: TSpeedButton;
  76.     SpeedButton3: TSpeedButton;
  77.     SpeedButton4: TSpeedButton;
  78.     SpeedButton5: TSpeedButton;
  79.     SpeedButton6: TSpeedButton;
  80.     SpeedButton7: TSpeedButton;
  81.     SpeedButton8: TSpeedButton;
  82.     SpeedButton9: TSpeedButton;
  83.     SpeedButton10: TSpeedButton;
  84.     SpeedButton11: TSpeedButton;
  85.     SpeedButton12: TSpeedButton;
  86.     SpeedButton13: TSpeedButton;
  87.     SpeedButton14: TSpeedButton;
  88.     SpeedButton15: TSpeedButton;
  89.     SpeedButton16: TSpeedButton;
  90.     SpeedButton17: TSpeedButton;
  91.     SpeedButton18: TSpeedButton;
  92.     SpeedButton19: TSpeedButton;
  93.     SpeedButton20: TSpeedButton;
  94.     SpeedButton21: TSpeedButton;
  95.     SpeedButton22: TSpeedButton;
  96.     SpeedButton23: TSpeedButton;
  97.     SpeedButton24: TSpeedButton;
  98.     SpeedButton25: TSpeedButton;
  99.     SpeedButton26: TSpeedButton;
  100.     SpeedButton27: TSpeedButton;
  101.     SpeedButton28: TSpeedButton;
  102.     SpeedButton29: TSpeedButton;
  103.     SpeedButton30: TSpeedButton;
  104.     SpeedButton31: TSpeedButton;
  105.     SpeedButton32: TSpeedButton;
  106.     SpeedButton33: TSpeedButton;
  107.     SpeedButton34: TSpeedButton;
  108.     SpeedButton35: TSpeedButton;
  109.     BitBtn1: TBitBtn;
  110.     DisabledBtn: TBitBtn;
  111.     NextPgBtn: TBitBtn;
  112.     ViewBtn: TBitBtn;
  113.     ConvertBtn: TBitBtn;
  114.     PathCombo: TComboBox;
  115.     FileView: TListView;
  116.     Label1: TLabel;
  117.     Label2: TLabel;
  118.     Label3: TLabel;
  119.     Label4: TLabel;
  120.     Label10: TLabel;
  121.     Label12: TLabel;
  122.     Label13: TLabel;
  123.     Label14: TLabel;
  124.     Label15: TLabel;
  125.     Label18: TLabel;
  126.     Label19: TLabel;
  127.     PrevPgBtn: TBitBtn;
  128.     Label9: TLabel;
  129.     CancelBtn2: TBitBtn;
  130.     GroupBox1: TGroupBox;
  131.     RBtn16C: TRadioButton;
  132.     RBtn256C: TRadioButton;
  133.     RBtnHiC: TRadioButton;
  134.     SEdtHeight: TSpinEdit;
  135.     SEdtWidth: TSpinEdit;
  136.     Label5: TLabel;
  137.     Label6: TLabel;
  138.     PopupMenu2: TPopupMenu;
  139.     OpenBookmark1: TMenuItem;
  140.     AddBookmark1: TMenuItem;
  141.     DeleteBookmark1: TMenuItem;
  142.     ToolBar1: TToolBar;
  143.     ImageList1: TImageList;
  144.     ToolButton1: TToolButton;
  145.     ToolButton2: TToolButton;
  146.     ToolButton3: TToolButton;
  147.     ToolButton4: TToolButton;
  148.     ToolButton5: TToolButton;
  149.     ToolButton6: TToolButton;
  150.     ToolButton8: TToolButton;
  151.     ToolButton9: TToolButton;
  152.     ImageList2: TImageList;
  153.  
  154.     procedure ViewBtnClick(Sender: TObject);
  155.     procedure ViewAsGlyph(const FileExt: string);
  156.     procedure StretchCheckClick(Sender: TObject);
  157.     procedure FormCreate(Sender: TObject);
  158.     procedure FormDestroy(Sender: TObject);
  159.     procedure SaveBtnClick(Sender: TObject);
  160.     procedure SpeedButtonMouseDown(Sender: TObject;
  161.       Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  162.     procedure NextPgBtnClick(Sender: TObject);
  163.     procedure DisabledBtnClick(Sender: TObject);
  164.     procedure OKBtnClick(Sender: TObject);
  165.     procedure CopyImageBtnClick(Sender: TObject);
  166.     procedure ClearBtnClick(Sender: TObject);
  167.     procedure CancelBtnClick(Sender: TObject);
  168.     procedure PageControl1Change(Sender: TObject);
  169.     procedure DisplayHint(Sender: TObject);
  170.     procedure FormActivate(Sender: TObject);
  171.     procedure BookMkBtnClick(Sender: TObject);
  172.     procedure AddBookMkBtnClick(Sender: TObject);
  173.     procedure DelBookMkBtnClick(Sender: TObject);
  174.     procedure LbxBookMarkDblClick(Sender: TObject);
  175.     procedure ConvertBtnClick(Sender: TObject);
  176.     procedure LbxBookMarkDragOver(Sender, Source: TObject; X, Y: Integer;
  177.       State: TDragState; var Accept: Boolean);
  178.     procedure LbxBookMarkDragDrop(Sender, Source: TObject; X, Y: Integer);
  179.     procedure LbxBookMarkMouseDown(Sender: TObject; Button: TMouseButton;
  180.       Shift: TShiftState; X, Y: Integer);
  181.  
  182.     procedure CreateImages;
  183.     procedure PathComboUpdate(cPath: TFileName); //2.0
  184.     procedure PathComboChange(Sender: TObject); //2.0
  185.     procedure PathComboDrawItem(Control: TWinControl; Index: Integer;
  186.       Rect: TRect; State: TOwnerDrawState); //2.0
  187.     procedure PathComboClick(Sender: TObject); //2.0
  188.     procedure FileViewBuildList(cDir: string); //2.0
  189.     procedure FileViewCompare(Sender: TObject; Item1, Item2: TListItem;
  190.       Data: Integer; var Compare: Integer); //2.0
  191.     procedure FileViewClick(Sender: TObject); //2.0
  192.     procedure FileViewDblClick(Sender: TObject); //2.0
  193.     procedure FileViewChange(Sender: TObject; Item: TListItem;
  194.       Change: TItemChange); //2.0
  195.     procedure LoadBookMarks;
  196.     procedure UpdateBookMarks;
  197.     procedure AddBookMark(NewDir: string);
  198.     procedure LoadGlyphs; //2.0
  199.     procedure ClearGlyphs;
  200.     procedure DrawGlyphs; //2.0
  201.     procedure ReleaseBtn;
  202.     procedure PrevPgBtnClick(Sender: TObject);
  203.     procedure CancelBtn2Click(Sender: TObject);
  204.     procedure RBtnClick(Sender: TObject);
  205.     procedure ResetTabSheet3;
  206.  
  207.   private
  208.   { Private declarations }
  209.     DefaultDir: string;
  210.     Icon1: TIcon;
  211.     IniFile: TIniFile;
  212.     LastDirIndex: integer;
  213.     sSbName: string;
  214.     Title: string;
  215.     GlyphList: TStringList; //2.0
  216.     GlyphIdx: integer; //2.0
  217.     MaxIdx: integer; //2.0
  218.     EmptyBtn: integer; //2.0
  219.     sImages: TImageList; //2.0
  220. //    mySImgList: TImageList;   //2.1
  221. //    SGoUpBmp: TBitmap;        //2.1
  222. //    SGoUpIdx: integer;        //2.1
  223.     SelectedPath: TFileName; //2.0
  224.     SelectedFile: TFileName; //2.0
  225.     Drives: set of 0..25; //2.0
  226.     SelPath: TFileName;  //2.2
  227.   end;
  228.  
  229. var
  230.   PEMainForm: TPEMainForm;
  231.  
  232. implementation
  233.  
  234. {$R *.DFM}
  235.  
  236. uses LsPicEditorViewD3;
  237.  
  238.  
  239. { ================== Global Functions/Procedures ================== }
  240.  
  241. function NumPos(a: Char; b: string; c: integer): integer;
  242. var
  243.   i, az: integer;
  244. begin
  245.   Result := MaxInt;
  246.   if Length(b) > 0 then
  247.   begin
  248.     az := 0;
  249.     for i := 1 to Length(b) do
  250.       if b[i] = a then
  251.       begin
  252.         inc(az);
  253.         if az = c then
  254.         begin
  255.           Result := i;
  256.           exit;
  257.         end;
  258.       end;
  259.   end;
  260. end; //NumPos
  261.  
  262. function GetCount(a: Char; b: string): integer;
  263. var
  264.   i: integer;
  265. begin
  266.   Result := 0;
  267.   if Length(b) > 0 then
  268.     for i := 1 to Length(b) do
  269.       if b[i] = a then
  270.         inc(Result);
  271. end; //GetCount
  272.  
  273. function AddSlash(Path: string): string;
  274. begin
  275.   if Path = '' then exit;
  276.   if Path[Length(Path)] <> '\' then
  277.     Result := Path + '\'
  278.   else
  279.     Result := Path;
  280. end; //AddSlash
  281.  
  282. function DelSlash(Path: string): string;
  283. begin
  284.   Result := Path;
  285.   if Path <> '' then
  286.     if Path[Length(Path)] = '\' then
  287.       Delete(Result, Length(Path), 1);
  288. end; //DelSlash
  289.  
  290. // Display applications Hints in StatusBar1
  291. procedure TPEMainForm.DisplayHint(Sender: TObject);
  292. begin
  293.   StatusBar1.SimpleText := GetLongHint(Application.Hint);
  294. end; //DisplayHint
  295.  
  296. procedure TPEMainForm.FormCreate(Sender: TObject);
  297. var
  298.   WinDir: String;
  299. begin
  300.   with LbxBookMark do begin
  301.     Left := 2;
  302.     Top := 2;
  303.     Height := 120;
  304.     Width := 460; //334;  //2.1
  305.     Visible := False;
  306.   end;
  307.   Panel4.Height := 36;
  308.   Panel4.Width := 36;
  309.   Panel8.Height := 36;
  310.   Panel8.Width := 36;
  311.   Icon1 := TIcon.Create;
  312.   Application.OnHint := DisplayHint;
  313.   Title := 'Property Editor (Bitmap & Picture)';
  314.   Integer(Drives) := GetLogicalDrives;
  315.   CreateImages;
  316.   DefaultDir := GetCurrentDir;
  317.   SetLength(WinDir, MAX_PATH);
  318.   SetLength(WinDir, GetWindowsDirectory(PChar(WinDir), MAX_PATH));
  319.   WinDir := AddSlash(WinDir);
  320.   if FileExists(WinDir + 'LsPEPicture.ini')  then  //2.3>>
  321.   begin
  322.     LoadBookMarks;
  323.     if LbxBookMark.Items[LastDirIndex] <> '' then
  324.       SelectedPath := LbxBookMark.Items[LastDirIndex];
  325.   end
  326.   else begin
  327.     MessageDlg('ERROR - File LsPEPicture.ini not found' + #13 +
  328.                'hence BookMards will not work' , mtERROR, [mbOK], 0);
  329.     SelectedPath := DefaultDir;
  330.   end;  //2.3
  331.   PathComboUpdate(SelectedPath); //2.0
  332.   FileViewBuildList(SelectedPath); //2.0
  333. end; //FormCreate
  334.  
  335. procedure TPEMainForm.FormActivate(Sender: TObject);
  336. begin
  337.   PageControl1.ActivePage := TabSheet1;
  338. end; //FormActivate
  339.  
  340. procedure TPEMainForm.FormDestroy(Sender: TObject);
  341. begin
  342.   sImages.Free;
  343. //  SGoupBmp.Free;
  344.   GlyphList.Free;
  345.   ChDir(DefaultDir);
  346. end; //FormDestroy
  347.  
  348. // If it is a Bitmap, Load it to Image2 and BitBtn1 as Glyph
  349. procedure TPEMainForm.ViewAsGlyph(const FileExt: string);
  350. begin
  351.   if (PageControl1.ActivePage = TabSheet2) and (FileExt = '.BMP') then
  352.   begin
  353.     Image2.Picture := Image1.Picture;
  354.     BitBtn1.Glyph := Image1.Picture.Bitmap;
  355.   end;
  356. end; //ViewAsGlyph
  357.  
  358. // To view the picture at its fullsize
  359. procedure TPEMainForm.ViewBtnClick(Sender: TObject);
  360. begin
  361.   if (Image1.Picture.Width < 620) and
  362.     (Image1.Picture.Height < 440) then
  363.   begin
  364.     PEViewForm.Width := Image1.Picture.Width + 20;
  365.     PEViewForm.Height := Image1.Picture.Height + 40;
  366.   end
  367.   else begin
  368.     PEViewForm.Width := 640;
  369.     PEViewForm.Height := 480;
  370.     PEViewForm.HorzScrollBar.Range := Image1.Picture.Width;
  371.     PEViewForm.VertScrollBar.Range := Image1.Picture.Height;
  372.   end;
  373.   PEViewForm.Caption := Label1.Caption;
  374.   PEViewForm.VFrmImage1.Picture := Image1.Picture;
  375.   if not PEViewForm.Visible then
  376.     PEViewForm.Show
  377.   else PEViewForm.Hide;
  378. end; //ViewBtnClick
  379.  
  380. // Stretch the picture size to fit Image1 if StretchCheckBox Checked
  381. procedure TPEMainForm.StretchCheckClick(Sender: TObject);
  382. begin
  383.   Image1.Stretch := StretchCheck.Checked;
  384. end; //StretchCheckClick
  385.  
  386. // Save the selected Picture to a file
  387. procedure TPEMainForm.SaveBtnClick(Sender: TObject);
  388. begin
  389.   if Image1.Picture.Bitmap.Empty then
  390.   begin
  391.     MessageDlg('No Image selected', mtError, [mbOK], 0);
  392.     exit;
  393.   end;
  394.   if Label1.Caption <> '' then
  395.     SaveDialog1.Filename := Label1.Caption;
  396.   SaveDialog1.Title := 'Save selected picture to file';
  397.   SaveDialog1.InitialDir := SelectedPath;  //GetCurrentDir;  //2.3
  398.   SaveDialog1.Filter := 'All Files(*.*)|*.*';  //2.1
  399.   SaveDialog1.DefaultExt := '.bmp';
  400.   if SaveDialog1.Execute then
  401.   begin
  402.     Image1.Picture.SaveToFile(SaveDialog1.Filename);
  403.     SelectedPath := ExtractFilePath(SaveDialog1.Filename);  //2.3
  404.   end else
  405.     ModalResult := mrNone;
  406. end; //SaveBtnClick
  407.  
  408.  
  409. {========== Draw bitmaps in speedbuttons on TabSheet2 as glyphs ==========}
  410.  
  411. // Load all bmp file names in the current directory into GlyphList;
  412. procedure TPEMainForm.LoadGlyphs; //2.0
  413. var
  414.   SRec: TSearchRec;
  415.   Rslt: word;
  416.   CurPath: string;
  417.   OldCur: TCursor;
  418. begin
  419.   GlyphIdx := 0;
  420.   MaxIdx := 0;
  421.   GlyphList := TStringList.Create;
  422.   GlyphList.Clear;
  423.   OldCur := Screen.Cursor;
  424.   Screen.Cursor := crHourGlass;
  425.   CurPath := AddSlash(SelectedPath);
  426.   FillChar(SRec, SizeOf(SRec), 0);
  427.   try
  428.     Rslt := FindFirst(CurPath + '*.bmp', faAnyFile, SRec);
  429.     while Rslt = 0 do
  430.     begin
  431.       GlyphList.Add(CurPath + SRec.Name);
  432.       MaxIdx := MaxIdx + 1;
  433.       Rslt := FindNext(SRec);
  434.     end;
  435.     FindClose(Srec);
  436.   finally
  437.     Screen.Cursor := OldCur;
  438.   end;
  439.   DrawGlyphs;
  440.   NextPgBtn.Enabled := True;
  441. end; //LoadGlyphs
  442.  
  443. // Draw glyphs into Speedbuttons on TabSheet2
  444. procedure TPEMainForm.DrawGlyphs; //2.0
  445. var
  446.   i, j: integer;
  447. begin
  448.   i := 0;
  449.   j := 0;
  450.   while i < ComponentCount do
  451.   begin
  452.     if Components[i] is TSpeedButton then
  453.       with Components[i] as TSpeedButton do
  454.       begin
  455.         if GlyphIdx < (MaxIdx - 1) then
  456.         begin
  457.           Glyph.LoadFromFile(GlyphList.Strings[GlyphIdx]);
  458.           NumGlyphs := Glyph.width div 16;
  459.           Hint := ExtractFileName(GlyphList.Strings[GlyphIdx]); //tsRec.Name;
  460.           Visible := True;
  461.           Down := False;
  462.           inc(GlyphIdx);
  463.           inc(j);
  464.         end
  465.         else
  466.           Visible := False;
  467.       end;
  468.     inc(i);
  469.   end;
  470.   EmptyBtn := 35 - j;
  471. end; //DrawGlyphs
  472.  
  473. // Clear all Glyphs in SpeedButtons on TabSheet2
  474. procedure TPEMainForm.ClearGlyphs;
  475. var
  476.   i: integer;
  477. begin
  478.   i := 0;
  479.   while i < ComponentCount do
  480.   begin
  481.     if Components[i] is TSpeedButton then
  482.     begin
  483.       DeleteObject(TSpeedButton(Components[i]).Glyph.ReleaseHandle);
  484.       TSpeedButton(Components[i]).Glyph := nil;
  485.     end;
  486.     inc(i);
  487.   end;
  488. end; //ClearGlyphs
  489.  
  490. // Release all SpeedButtons on TabSheet2
  491. procedure TPEMainForm.ReleaseBtn;
  492. var
  493.   i: integer;
  494. begin
  495.   i := 0;
  496.   while i < ComponentCount do
  497.   begin
  498.     if Components[i] is TSpeedButton then
  499.     begin
  500.       TSpeedButton(Components[i]).Down := False;
  501.     end;
  502.     inc(i);
  503.   end;
  504. end; //ReleaseBtn
  505.  
  506. // MouseDownEvent - LEFT-Button to select Glyph
  507. //                  RIGHT-Button to activate PopupMenu1
  508. procedure TPEMainForm.SpeedButtonMouseDown(Sender: TObject;
  509.   Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  510. var
  511.   PtPos: TPoint;
  512.   SelPict: TBitmap;
  513.   SelFile: string;
  514.   i: integer;
  515. begin
  516.   SelFile := '';
  517.   PtPos := Point(X, Y);
  518.   PtPos := TSpeedButton(Sender).ClientToScreen(PtPos);
  519.   sSBName := TSpeedButton(Sender).Name;
  520.   if Button = mbLeft then
  521.   begin
  522.     SelPict := TSpeedButton(Sender).Glyph;
  523.     SelFile := TSpeedButton(Sender).Hint;
  524.  
  525.     with FileView do
  526.     begin
  527.       FileView.SetFocus;
  528.       FileView.Selected := nil;  //2.2
  529.       for i := 0 to (Items.Count - 1) do
  530.       begin
  531.         if (Items[i].Caption = SelFile) then
  532.         begin
  533.           Items[i].Selected := True;
  534.           SelectedFile := Items[i].SubItems[0];
  535.           Break;
  536.         end;
  537.       end;
  538.     end;
  539.  
  540.     Image1.Picture.Graphic := SelPict;
  541.     Image2.Picture.Graphic := SelPict;
  542.     Label1.Caption := SelFile;
  543.     Label3.Caption := Format('(%d x %d)',
  544.       [Image1.Picture.Width, Image1.Picture.Height]);
  545.     Caption := Title + '  -  ' + SelFile;
  546.     ViewAsGlyph('.BMP');
  547.   end
  548.   else if Button = mbRight then
  549.   begin
  550.     NumGlyph1.Caption := 'Num Glyphs = ' +
  551.       IntToStr(TSpeedButton(Sender).NumGlyphs);
  552.     PopupMenu1.Popup(PtPos.x + 10, PtPos.y + 6);
  553.   end;
  554. end; //SpeedButtonMouseDown
  555.  
  556. // Display next page of Glyphs
  557. procedure TPEMainForm.NextPgBtnClick(Sender: TObject);
  558. begin
  559.   PrevPgBtn.Enabled := True;
  560.   Image1.Picture.graphic := nil;
  561.   Label1.Caption := '';
  562.   Label3.Caption := '';
  563.   Caption := Title;
  564.   BitBtn1.Enabled := True;
  565.   BitBtn1.Glyph := nil;
  566.   Image2.Picture := nil;
  567.   DisabledBtn.Tag := 0;
  568.   DrawGlyphs;
  569.   if GlyphIdx >= (MaxIdx - 1) then //2.0
  570.   begin
  571.     NextPgBtn.Enabled := False;
  572.     Exit;
  573.   end;
  574. end; //NextPgBtnClick
  575.  
  576. // Display prior page of Glyphs
  577. procedure TPEMainForm.PrevPgBtnClick(Sender: TObject); //2.0
  578. begin
  579.   NextPgBtn.Enabled := True;
  580.   Image1.Picture.graphic := nil;
  581.   Label1.Caption := '';
  582.   Label3.Caption := '';
  583.   Caption := Title;
  584.   BitBtn1.Enabled := True;
  585.   BitBtn1.Glyph := nil;
  586.   Image2.Picture := nil;
  587.   DisabledBtn.Tag := 0;
  588.   if EmptyBtn > 0 then
  589.     GlyphIdx := GlyphIdx - 70 + EmptyBtn
  590.   else
  591.     GlyphIdx := GlyphIdx - 70;
  592.   if GlyphIdx <= 0 then
  593.   begin
  594.     GlyphIdx := 0;
  595.     PrevPgBtn.Enabled := False;
  596.   end;
  597.   DrawGlyphs;
  598. end; //PrevPgBtnClick
  599.  
  600. // Enable or Disable Glyphs in SpeedButtons.
  601. procedure TPEMainForm.DisabledBtnClick(Sender: TObject);
  602. var
  603.   i: integer;
  604. begin
  605.   with DisabledBtn do
  606.   begin
  607.     if Tag = 0 then
  608.     begin
  609.       Font.Color := clBlue;
  610.       Caption := 'Enable';
  611.       Hint := '| Enable Glyphs in SpeedButtons';
  612.       Tag := 1;
  613.     end
  614.     else begin
  615.       Font.Color := clRed;
  616.       Caption := 'Disable';
  617.       Hint := '| Disable Glyphs in SpeedButtons';
  618.       Tag := 0;
  619.     end;
  620.   end;
  621.   i := 0;
  622.   while i < ComponentCount do
  623.   begin
  624.     if Components[i] is TSpeedButton then
  625.       TSpeedButton(Components[i]).Enabled := (DisabledBtn.Tag = 0);
  626.     inc(i);
  627.   end;
  628.   BitBtn1.Enabled := (DisabledBtn.Tag = 0);
  629. end; //DisabledBtnClick
  630.  
  631. // Copy the selected Bitmap/Glyph to Clipboard
  632. procedure TPEMainForm.CopyImageBtnClick(Sender: TObject);
  633. begin
  634.   if Image1.Picture.Bitmap.Empty then
  635.   begin
  636.     MessageDlg('No Image selected', mtError, [mbOK], 0);
  637.     exit;
  638.   end
  639.   else if (UpperCase(ExtractFileExt(Label1.Caption)) = '.ICO') then
  640.   begin
  641.     MessageDlg('ClipBoard does not support Icons', mtInformation, [mbOK], 0);
  642.     exit;
  643.   end else
  644.     ClipBoard.Assign(Image1.Picture.Graphic);
  645. end; //CopyImageBtnClick
  646.  
  647. // Clear the displayed Bitmaps and/or Glyphs
  648. procedure TPEMainForm.ClearBtnClick(Sender: TObject);
  649. begin
  650.   Image1.Picture := nil;
  651.   Image2.Picture := nil;
  652.   Image3.Picture := nil;
  653.   Image4.Picture := nil;
  654.   BitBtn1.Glyph := nil;
  655.   Label1.Caption := '';
  656.   Label3.Caption := '';
  657.   Caption := Title;
  658.   ReleaseBtn;
  659. end; //ClearBtnClick
  660.  
  661. // Select the Bitmap as Glyph, and write current BookMark to IniFile
  662. procedure TPEMainForm.OKBtnClick(Sender: TObject);
  663. begin
  664.   IniFile := TIniFile.Create('LsPEPicture.ini');
  665.   with IniFile do
  666.   try
  667.     WriteInteger('General', 'LastDirIndex', LbxBookMark.ItemIndex);
  668.   finally
  669.     IniFile.Free;
  670.   end; { finally }
  671.   ChDir(DefaultDir);
  672.   ModalResult := mrOK;
  673. end; //OKBtnClick
  674.  
  675. // Cancel current operation
  676.  
  677. procedure TPEMainForm.CancelBtnClick(Sender: TObject);
  678. begin
  679.   ChDir(DefaultDir);
  680.   ModalResult := mrCancel;
  681. end; //CancelBtnClick
  682.  
  683.  
  684. // Draw Glyphs in SpeedButtons when change to TabSheet2
  685. procedure TPEMainForm.PageControl1Change(Sender: TObject);
  686. begin
  687.   if PageControl1.ActivePage = TabSheet2 then
  688.   begin
  689.     ViewAsGlyph('.BMP');
  690.     LoadGlyphs;
  691.   end
  692.   else if PageControl1.ActivePage = TabSheet3 then
  693.   begin
  694.     ResetTabSheet3; //2.1
  695.     RBtn256C.Checked := True; //2.1
  696.   end
  697.   else begin
  698.     DeleteObject(BitBtn1.Glyph.ReleaseHandle);
  699.     BitBtn1.Glyph := nil;
  700.     ClearGlyphs;
  701.   end; { else }
  702. end; //PageControl1Change
  703.  
  704. // Open or Close BookMark List (LbxBookMark)
  705. procedure TPEMainForm.BookMkBtnClick(Sender: TObject);
  706. begin
  707.   if not LbxBookMark.Visible then
  708.   begin
  709.     LbxBookMark.Visible := True;
  710.     OpenBookMark1.Caption := 'Close Bookmarks'; //2.1
  711.   end else
  712.   begin
  713.     LbxBookMark.Visible := False;
  714.     OpenBookMark1.Caption := 'Open Bookmarks'; //2.1
  715.   end;
  716. end; //BookMkBtnClick
  717.  
  718. { ========================= BookMarks ============================= }
  719.  
  720. // Load BookMarks from IniFile (LsPEPicture.ini) to BookMark List(LbxBookMark)
  721. procedure TPEMainForm.LoadBookMarks;
  722. var
  723.   i,
  724.     BookMarksCount: Integer;
  725. begin
  726.   IniFile := TIniFile.Create('LsPEPicture.ini');
  727.   with IniFile do
  728.   try
  729.     LbxBookMark.Items.Clear;
  730.     LbxBookMark.ItemIndex := 0;
  731.     BookMarksCount := ReadInteger('General', 'BookMarksCount', 0);
  732.     for i := 1 to BookMarksCount do
  733.     begin
  734.       LbxBookMark.ItemIndex := i - 1;
  735.       LbxBookMark.Items.Add(ReadString('Path', 'Directory' +
  736.         IntToStr(i), ''));
  737.     end;
  738.     LastDirIndex := ReadInteger('General', 'LastDirIndex', -1);  //2.3
  739.     if (LastDirIndex = -1) and
  740.        (ReadString('Path', 'Directory1', '') <> '') then
  741.       LastDirIndex := 0;  //2.3
  742. //    LbxBookMark.ItemIndex := LastDirIndex;
  743.   finally
  744.     Free;
  745.   end;
  746.   LbxBookMark.ItemIndex := LastDirIndex;
  747. end; //LoadBookMarks
  748.  
  749. // Add current DirectoryListBox's directory to BookMark List
  750. procedure TPEMainForm.AddBookMkBtnClick(Sender: TObject);
  751. var
  752.   CurDir: string;
  753. begin
  754.   if SelectedPath = '' then //2.0
  755.   begin
  756.     MessageDlg('No Directory selected', mtError, [mbOK], 0);
  757.     exit;
  758.   end;
  759.   CurDir := AddSlash(SelectedPath); //2.0
  760.   if MessageDlg('Add the currently selected directory' + #13 +
  761.     '      "' + UpperCase(CurDir) + '"' + #13 +
  762.     'to the BookMarks List?' + #13, mtConfirmation,
  763.     [mbYes, mbNo], 0) = mrNo then
  764.     exit;
  765.   AddBookMark(CurDir);
  766. end; //AddBookMkBtnClick
  767.  
  768. // Add a Directory(NewDir) to BookMark List
  769. procedure TPEMainForm.AddBookMark(NewDir: string);
  770. begin
  771.   NewDir := LowerCase(NewDir);
  772.   LbxBookMark.Items.Add(NewDir);
  773.   LbxBookMark.ItemIndex := Pred(LbxBookMark.Items.Count);
  774.   IniFile := TIniFile.Create('LsPEPicture.ini');
  775.   with IniFile do
  776.   try
  777.     WriteInteger('General', 'BookMarksCount', LbxBookMark.Items.Count);
  778.     WriteString('Path', 'Directory' + IntToStr(LbxBookMark.Items.Count),
  779.       NewDir);
  780.   finally
  781.     Free;
  782.   end;
  783. end; //AddBookMark
  784.  
  785. // Delete selected BookMark from the BookMarks List
  786. procedure TPEMainForm.DelBookMkBtnClick(Sender: TObject);
  787. var
  788.   OldIndex: integer;
  789. begin
  790.   if (LbxBookMark.Items.Count = 0) or (LbxBookMark.ItemIndex = -1) or
  791.     (LbxBookMark.Visible = False) then
  792.   begin
  793.     MessageDlg('No Bookmark selected', mtError, [mbOK], 0);
  794.     exit;
  795.   end;
  796.   OldIndex := LbxBookMark.ItemIndex;
  797.   if MessageDlg('Are you sure you want to delete' + #13 + '    "' +
  798.     UpperCase(LbxBookMark.Items[OldIndex]) +
  799.     '"' + #13 + 'from the BookMarks List ?', mtConfirmation,
  800.     [mbYes, mbNo], 0) = mrYes then
  801.   try
  802.     LbxBookMark.Items.Delete(OldIndex);
  803.     LbxBookMark.ItemIndex := 0;
  804.     UpdateBookMarks;
  805.   finally
  806.     LbxBookMark.Visible := False;
  807.     LoadBookMarks;
  808.   end;
  809. end; //DelBookMkBtnClick
  810.  
  811. // Select a BookMark as DirectoryListBox1's Directory
  812. procedure TPEMainForm.LbxBookMarkDblClick(Sender: TObject);
  813. var
  814.   SelDir: string;
  815. begin
  816.   SelDir := LbxBookMark.Items[LbxBookMark.ItemIndex];
  817.   if DirectoryExists(SelDir) then
  818.   begin
  819.     SelectedPath := SelDir; //2.0
  820.     PathComboUpdate(SelDir); //2.0
  821.     FileViewBuildList(SelDir); //2.0
  822.     PageControl1.ActivePage := TabSheet1; //2.0
  823.     BookMkBtnClick(Sender);  //2.3
  824.   end else
  825.     MessageDlg('Selected Directory does not exist', mtInformation, [mbOK], 0);
  826.   LbxBookMark.Visible := False;
  827. end; //LbxBookMarkDblClick
  828.  
  829. { ========== Drag-n-Drop BookMarks in the BookMarks List ========== }
  830.  
  831. procedure TPEMainForm.LbxBookMarkDragOver(Sender, Source: TObject; X,
  832.   Y: Integer; State: TDragState; var Accept: Boolean);
  833. var
  834.   DropPos: Integer;
  835. begin
  836.   if Source = LbxBookMark then
  837.   begin
  838.     DropPos := LbxBookMark.ItemAtPos(Point(X, Y), False);
  839.     Accept := (DropPos > -1) and (DropPos < LbxBookMark.Items.Count);
  840.   end
  841.   else Accept := False;
  842. end; //LbxBookMarkDragOver
  843.  
  844. procedure TPEMainForm.LbxBookMarkDragDrop(Sender, Source: TObject; X,
  845.   Y: Integer);
  846. var
  847.   OldPos: Integer;
  848.   NewPos: Integer;
  849. begin
  850.   if Source = LbxBookMark then
  851.   begin
  852.     OldPos := LbxBookMark.ItemIndex;
  853.     NewPos := LbxBookMark.ItemAtPos(Point(X, Y), False);
  854.     if (NewPos > -1) and (NewPos <> OldPos) then
  855.       LbxBookMark.Items.Move(OldPos, NewPos);
  856.     UpdateBookMarks;
  857.     LbxBookMark.ItemIndex := NewPos;
  858.   end;
  859. end; //LbxBookMarkDragDrop
  860.  
  861. procedure TPEMainForm.LbxBookMarkMouseDown(Sender: TObject;
  862.   Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  863. var
  864.   DragItem: Integer;
  865. begin
  866.   if Button = mbLeft then
  867.   begin
  868.     DragItem := LbxBookMark.ItemAtPos(Point(X, Y), False);
  869.     if (DragItem > -1) and (DragItem < LbxBookMark.Items.Count) then
  870.       LbxBookMark.BeginDrag(False);
  871.   end
  872.   else if Button = mbRight then
  873.     LbxBookMark.Visible := False;
  874. end; //LbxBookMarkMouseDown
  875.  
  876. // Update IniFile (LsPEPicture.ini) after changing or deleting BookMarks
  877. procedure TPEMainForm.UpdateBookMarks;
  878. var
  879.   i: integer;
  880. begin
  881.   IniFile := TIniFile.Create('LsPEPicture.ini');
  882.   with IniFile do
  883.   try
  884.     WriteInteger('General', 'BookMarksCount', LbxBookMark.Items.Count);
  885.     EraseSection('Path');
  886.     LbxBookMark.ItemIndex := 0;
  887.     for i := 1 to LbxBookMark.Items.Count do begin
  888.       LbxBookMark.ItemIndex := i - 1;
  889.       WriteString('Path', 'Directory' + IntToStr(i),
  890.         LowerCase(LbxBookMark.Items[Pred(i)]));
  891.     end; // for
  892.   finally
  893.     Free;
  894.   end;
  895. end; //UpdateBookMarks
  896.  
  897.  
  898. { ==================== Convert Icons to Bitmaps =================== }
  899.  
  900. procedure TPEMainForm.ConvertBtnClick(Sender: TObject);
  901. var
  902.   Rect1: TRect;
  903.   Bmp1,
  904.     Bmp2: TBitmap;
  905. const
  906.   FExt = '.bmp';
  907. begin
  908.   Bmp1 := TBitmap.Create;
  909.   Bmp2 := TBitmap.Create;
  910.   Image4.Picture := nil;
  911.   SEdtWidth.Update;
  912.   SEdtHeight.Update;
  913.   if SEdtWidth.Value > 32 then
  914.     Panel8.Width := SEdtWidth.Value + 4;
  915.   if SEdtHeight.Value > 32 then
  916.     Panel8.Height := SEdtHeight.Value + 4;
  917.   if Icon1.Width > 32 then
  918.     Panel4.Width := Icon1.Width + 4;
  919.   if Icon1.Height > 32 then
  920.     Panel4.Height := Icon1.Height + 4;
  921.   with Rect1 do
  922.   begin
  923.     Top := 0;
  924.     Left := 0;
  925.     Right := SEdtWidth.Value;
  926.     Bottom := SEdtHeight.Value;
  927.   end;
  928.  
  929.   if Image3.Picture <> nil then
  930.   try
  931.     with Image3.Picture do
  932.     begin
  933.       Bmp1.Height := Icon.Height;
  934.       Bmp1.Width  := Icon.Width;
  935.       Bmp1.Canvas.Draw(0, 0, Icon);
  936.     end;
  937.  
  938.     if RBtn16C.Checked then
  939.       Bmp2.PixelFormat := pf4bit
  940.     else if RBtn256C.Checked then
  941.       Bmp2.PixelFormat := pf8bit
  942.     else if RBtnHiC.Checked then
  943.       Bmp2.PixelFormat := pf24bit;
  944.  
  945.     with Bmp2 do
  946.     begin
  947.       Width := SEdtWidth.Value;
  948.       Height := SEdtHeight.Value;
  949.       Canvas.StretchDraw(Rect1, Bmp1);
  950.     end;
  951.     Image4.Picture.Bitmap.Assign(Bmp2);
  952.     Image1.Picture.Bitmap.Assign(Bmp2);
  953.  
  954.     Label1.Caption :=
  955.       ChangeFileExt(ExtractFileName(FileView.Selected.SubItems[0]), FExt);
  956.     Caption := Title + '  -  ' + Label1.Caption;
  957.     Label3.Caption := Format('(%d x %d)', [Image1.Picture.Width,
  958.       Image1.Picture.Height]);
  959.     ConvertBtn.Enabled := False;
  960.   finally
  961.     Bmp1.Free;
  962.     Bmp2.Free;
  963.   end;
  964. end; //ConvertBtnClick
  965.  
  966. procedure TPEMainForm.CancelBtn2Click(Sender: TObject);
  967. begin
  968.   Image3.Picture := nil;
  969.   Image4.Picture := nil;
  970.   ResetTabSheet3; //2.1
  971.   RBtn256C.Checked := True; //2.1
  972. end;  //CancelBtn2Click
  973.  
  974. procedure TPEMainForm.ResetTabSheet3; //2.1 >>
  975. begin
  976.   Image3.Picture := nil;
  977.   Panel4.Height := 36;
  978.   Panel4.Width := 36;
  979.   Panel8.Height := 36;
  980.   Panel8.Width := 36;
  981.   SEdtHeight.Value := 32;
  982.   SEdtWidth.Value := 32;
  983. end;  //ResetTabSheet3  //2.1 <<
  984.  
  985. procedure TPEMainForm.RBtnClick(Sender: TObject); //2.1
  986. begin
  987.   Image3.Picture := nil;
  988. end;  //RBtnClick  //2.1
  989.  
  990.  
  991. { ================== PathCombo and FileView ======================= }
  992.  
  993.  
  994. procedure TPEMainForm.CreateImages; //2.0
  995. var
  996.   SysIL: UInt;
  997.   SFI: TSHFileInfo;
  998. begin
  999.   sImages := TImageList.Create(self);
  1000.   SysIL := SHGetFileInfo('', 0, SFI, SizeOf(SFI), SHGFI_SYSICONINDEX
  1001.     or SHGFI_SMALLICON);
  1002.   if SysIL <> 0 then
  1003.   begin
  1004.     sImages.Handle := SysIL;
  1005.     sImages.ShareImages := True;
  1006.   end;
  1007.   FileView.SmallImages := sImages;
  1008. {**
  1009.   mySImgList := TImageList.Create(Self);
  1010.   mySImgList.Assign(sImages);
  1011.   SGoupBmp := TBitmap.Create;
  1012.   SGoupBmp.LoadFromResourceName(hInstance, 'Parent');
  1013.   SGoupIdx := mySImgList.Add(SGoupBmp, nil);
  1014.   mySImgList.ShareImages := False;
  1015.   FileView.SmallImages := mySImgList;
  1016. **}
  1017. end; //CreateImages
  1018.  
  1019. procedure TPEMainForm.PathComboUpdate(cPath: TFileName); //2.0
  1020. var
  1021.   Drv: byte;
  1022.   selDrv: byte;
  1023.   isDrive: boolean;
  1024.   i,
  1025.     cnt: integer;
  1026. begin
  1027.   SelPath := AddSlash(cPath);  //2.2
  1028.   with PEMainForm do
  1029.   begin
  1030.     PathCombo.items.beginupdate;
  1031.     PathCombo.items.clear;
  1032.     i := -1;
  1033.     isDrive := cPath = 'My Computer';
  1034.     selDrv := ord(upcase(cPath[1])) - ord('A');
  1035.     PathCombo.items.add('0:My Computer');
  1036.     for Drv := 0 to 25 do
  1037.       if Drv in drives then
  1038.       begin
  1039.         PathCombo.items.add('1:' + char(Drv + ord('A')) + ':\');
  1040.         if (not isDrive) and (Drv = selDrv) then
  1041.         begin
  1042.           for cnt := 1 to getcount('\', cPath) - 1 do
  1043.             PathCombo.items.add(IntToStr(cnt + 1) + ':'
  1044.               + copy(cPath, 1, numpos('\', cPath, cnt + 1)));
  1045.           i := PathCombo.items.count - 1;
  1046.         end;
  1047.         if isDrive then
  1048.           i := 0;
  1049.       end;
  1050. //    if i > -1 then                                     //2.2
  1051. //      PathCombo.items[i] := 'T' + PathCombo.items[i];  //2.2
  1052. //    PathCombo.itemindex := -1;                         //2.2
  1053.     PathCombo.items.endupdate;
  1054.     PathCombo.itemindex := i;
  1055.   end;
  1056. end; //PathComboUpdate
  1057.  
  1058. procedure TPEMainForm.PathComboChange(Sender: TObject); //2.0
  1059. var
  1060.   DirStr : string;
  1061. begin
  1062.   if PathCombo.droppeddown then exit;
  1063.   if PathCombo.itemindex <= 0 then exit;
  1064.   if PathCombo.itemindex = 0 then exit;
  1065.   DirStr := PathCombo.items[PathCombo.itemindex];
  1066.   DirStr := copy(DirStr, pos(':', DirStr) + 1, MaxInt);
  1067.   if (DirStr <> 'My Computer') and (not DirectoryExists(DirStr)) then
  1068.   begin
  1069.     MessageDlg('" ' + DirStr + ' "  is inaccessible !', mtInformation, [mbOK], 0);
  1070.     PathComboUpdate(SelPath);   //SelectedPath);  //2.2
  1071.     SelectedPath := SelPath;  //2.2
  1072.   end
  1073.   else begin
  1074.     SelectedPath := DirStr; //2.0
  1075.     PathComboUpdate(SelectedPath);
  1076.     FileViewBuildList(SelectedPath);
  1077.   end;
  1078. end; //PathComboChange
  1079.  
  1080. procedure TPEMainForm.PathComboDrawItem(Control: TWinControl;
  1081.   Index: Integer; Rect: TRect; State: TOwnerDrawState); //2.0
  1082. var
  1083.   DirName,
  1084.     DirStr: string;
  1085.   sfi: tshfileinfo;
  1086.   tab: integer;
  1087.   mode: integer;
  1088. begin
  1089.   fillchar(sfi, sizeof(tshfileinfo), 0);
  1090.   with PathCombo, PathCombo.canvas do
  1091.   begin
  1092.     Canvas.Font.Name := 'MS Sans Serif';
  1093.     Canvas.Font.Size := 8;
  1094.     mode := SHGFI_ICON or SHGFI_SMALLICON or SHGFI_DISPLAYNAME;
  1095.     DirStr := items[index];
  1096. //    if DirStr[1] = 'T' then           //2.2  >>
  1097. //    begin
  1098. //      DirStr := copy(DirStr, 2, maxint);
  1099. //      mode := mode or SHGFI_OPENICON;
  1100. //    end;                              //2.2 <<
  1101.     sImages.drawingstyle := dsTransparent;
  1102.     if odselected in state then
  1103.       sImages.drawingstyle := dsSelected;
  1104.     fillrect(rect);
  1105.     if DirStr = '0:My Computer' then
  1106.     begin
  1107.       sfi.szDisplayname := 'My Computer';
  1108.       sfi.iIcon := 15;
  1109.     end
  1110.     else
  1111.       SHGetFileInfo(pchar(copy(DirStr, pos(':', DirStr) + 1, maxint)), 0,
  1112.         sfi, sizeof(TSHFileInfo), mode);
  1113.     DirName := sfi.szDisplayName;
  1114.     tab := StrToInt(copy(DirStr, 1, pos(':', DirStr) - 1)) * 8;
  1115.  
  1116.     if not droppeddown then tab := 0;
  1117.  
  1118.     TextOut(Rect.Left + 20 + tab, Rect.Top + 2, DirName);
  1119.     sImages.draw(canvas, Rect.Left + 2 + tab, Rect.Top + 2, sfi.iIcon);
  1120.     sImages.drawingstyle := dsNormal;
  1121.   end;
  1122. end; //PathComboDrawItem
  1123.  
  1124. procedure TPEMainForm.PathComboClick(Sender: TObject); //2.0
  1125. begin
  1126.   with PathCombo do
  1127.   begin
  1128.     if ItemIndex = -1 then exit;
  1129.     if (ItemIndex = 0) then
  1130.       PathComboUpdate(SelectedPath)
  1131.     else begin
  1132.       SelectedPath := Items[ItemIndex];
  1133.       FileViewBuildList(SelectedPath);
  1134.     end;
  1135.   end;
  1136. end; //PathComboClick
  1137.  
  1138. procedure TPEMainForm.FileViewBuildList(cDir: string); //2.0
  1139. var
  1140.   CurDir,
  1141.     FName,
  1142.     FileName,
  1143.     FileOrDir: string;
  1144.   sfi: TSHFileInfo;
  1145.   hFindFile: THandle;
  1146.   Win32FD: TWin32FindData;
  1147.   OldCur: TCursor;
  1148. begin
  1149.   OldCur := Screen.Cursor;
  1150.   CurDir := AddSlash(cDir);
  1151.   hFindFile := FindFirstFile(PChar(CurDir + '*.*'), Win32FD);
  1152.   if hFindFile <> INVALID_HANDLE_VALUE then
  1153.   try
  1154.     Screen.Cursor := crHourGlass;
  1155.     FileView.Items.BeginUpdate;
  1156.     FileView.Items.Clear;
  1157.     repeat
  1158.       with Win32FD do
  1159.       begin
  1160.         if (dwFileAttributes and FILE_ATTRIBUTE_DIRECTORY > 0) then
  1161.           FileOrDir := 'dir'
  1162.         else
  1163.           FileOrDir := 'file';
  1164.  
  1165.         FName := StrPas(Win32FD.cFileName);
  1166.         FileName := CurDir + FName;
  1167.         if (FName = '.') then continue;
  1168.  
  1169.         SHGetFileInfo(PChar(FileName), 0, sfi, SizeOf(sfi),
  1170.           SHGFI_SYSICONINDEX or SHGFI_DISPLAYNAME);
  1171.  
  1172.         with FileView.Items.Add do
  1173.         begin
  1174.           if FName = '..' then
  1175.             Caption := ' ^Up 1 level'
  1176.           else
  1177.             Caption := FName;
  1178.           ImageIndex := sfi.iIcon;
  1179.           SubItems.Add(FileName);
  1180.           SubItems.Add(FileOrDir);
  1181.         end;
  1182.       end;
  1183.     until not FindNextFile(hFindFile, Win32FD);
  1184.   finally
  1185.     Windows.FindClose(hFindFile);
  1186.     FileView.Items.EndUpdate;
  1187.     Screen.Cursor := OldCur;
  1188.   end;
  1189. end; //FileViewBuildList
  1190.  
  1191. procedure TPEMainForm.FileViewCompare(Sender: TObject; Item1, Item2: TListItem;
  1192.   Data: Integer; var Compare: Integer); //2.0
  1193. var
  1194.   Caption1,
  1195.     Caption2: string;
  1196.   result: integer;
  1197. begin
  1198.   result := 0;
  1199.   if (Item1.SubItems[1] = 'dir') and (Item2.SubItems[1] <> 'dir') then
  1200.     Result := -1
  1201.   else if (Item1.SubItems[1] <> 'dir') and (Item2.SubItems[1] = 'dir') then
  1202.     Result := 1
  1203.   else
  1204.   begin
  1205.     Caption1 := AnsiUpperCase(Item1.Caption);
  1206.     Caption2 := AnsiUpperCase(Item2.Caption);
  1207.     if Caption1 > Caption2 then
  1208.       Result := 1
  1209.     else if Caption1 < Caption2 then
  1210.       Result := -1;
  1211.   end;
  1212.   Compare := Result;
  1213. end; //FileViewCompare
  1214.  
  1215. procedure TPEMainForm.FileViewDblClick(Sender: TObject); //2.0
  1216. var
  1217.   CurDir,
  1218.     NewDir: TFileName;
  1219. begin
  1220.   CurDir := '';
  1221.   NewDir := '';
  1222.   PageControl1.ActivePage := TabSheet1;
  1223.   with FileView do
  1224.   begin
  1225.     if (Selected <> nil) and (Selected.SubItems[1] = 'dir') then
  1226.     begin
  1227.       if Selected.Caption = ' ^Up 1 level' then
  1228.       begin
  1229.         CurDir := SelectedPath;
  1230.         CurDir := DelSlash(CurDir);
  1231.         NewDir := ExtractFilePath(CurDir);
  1232.       end
  1233.       else begin
  1234.         CurDir := Selected.SubItems[0];
  1235.         NewDir := AddSlash(CurDir);
  1236.       end;
  1237.       if NewDir <> '' then
  1238.       begin
  1239.         SelectedPath := NewDir;
  1240.         PathComboUpDate(SelectedPath);
  1241.         FileViewBuildList(SelectedPath);
  1242.       end
  1243.     end;
  1244.   end;
  1245. end; //FileViewDblClick
  1246.  
  1247. procedure TPEMainForm.FileViewClick(Sender: TObject); //2.0
  1248. var
  1249.   FileExt: string[4];
  1250. begin
  1251.   ClearBtnClick(Sender);
  1252.   PageControl1.ActivePage := TabSheet1;
  1253.   if FileView.Selected <> nil then //2.0
  1254.     SelectedFile := FileView.Selected.SubItems[0];
  1255.   FileExt := UpperCase(ExtractFileExt(SelectedFile));
  1256.  
  1257.   if (FileExt = '.BMP') or (FileExt = '.ICO') or
  1258.     (FileExt = '.WMF') then
  1259.   begin
  1260.     Image1.Picture.LoadFromFile(SelectedFile);
  1261.     Image2.Picture := Image1.Picture;
  1262.     Label1.Caption := ExtractFilename(SelectedFile);
  1263.     Caption := Title + '  -  ' + Label1.Caption;
  1264.  
  1265.     if (FileExt = '.BMP') then
  1266.     begin
  1267.       PageControl1.ActivePage := TabSheet1;
  1268.       Label3.Caption := Format('(%d x %d)', [Image1.Picture.Width,
  1269.         Image1.Picture.Height]);
  1270.       ViewAsGlyph(FileExt);
  1271.     end;
  1272.  
  1273.     if FileExt = '.ICO' then
  1274.     begin
  1275.       PageControl1.ActivePage := TabSheet3;
  1276.       Icon1 := Image1.Picture.Icon;
  1277.       Image3.Picture.Icon := Icon1;
  1278.       Image4.Picture := nil;
  1279.       ConvertBtn.Enabled := True;
  1280.     end;
  1281.  
  1282.     if FileExt = '.WMF' then
  1283.       PageControl1.ActivePage := TabSheet1;
  1284.   end;
  1285.   ReleaseBtn;
  1286. end;  //FileViewClick
  1287.  
  1288. procedure TPEMainForm.FileViewChange(Sender: TObject; Item: TListItem;
  1289.   Change: TItemChange); //2.0
  1290. var
  1291.   CurPath: string;
  1292. begin
  1293.   CurPath := AddSlash(SelectedPath);
  1294.   Image1.Picture.Graphic := nil;
  1295.   Image2.Picture.Graphic := nil;
  1296.   BitBtn1.Glyph := nil;
  1297.   Label1.Caption := '';
  1298.   Label3.Caption := '';
  1299.   Caption := Title;
  1300. end;  //FileViewChange
  1301.  
  1302.  
  1303.  
  1304. end.
  1305.  
  1306.