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