home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 December / Chip_2001-12_cd1.bin / zkuste / delphi / kompon / d3456 / LSPICEDT.ZIP / D4 / LsPicEditorMainD4.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2001-09-05  |  36.3 KB  |  1,311 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 LsPicEditorMainD4;
  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 LsPicEditorViewD4;
  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); //2.3>>
  318.   SetLength(WinDir, GetWindowsDirectory(PChar(WinDir), MAX_PATH));
  319.   WinDir := Addslash(WinDir);
  320.   if FileExists(WinDir + 'LsPEPicture.ini')  then
  321.   begin
  322.     LoadBookMarks;
  323.     if LbxBookMark.Items[LastDirIndex] <> '' then
  324.       SelectedPath := LbxBookMark.Items[LastDirIndex];
  325.   end else
  326.   begin
  327.     MessageDlg('ERROR - File LsPEPicture.ini not found' + #13 +
  328.                'hence BookMarks 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', -1);
  732.     if BookMarksCount = -1 then   //2.3>>
  733.     begin
  734.       MessageDlg('ERROR - LsPEPicture.ini is empty or' + #13 +
  735.                  '        not in Windows directory', mtError,
  736.                  [mbOK], 0);
  737.       exit;
  738.     end;  //2.3<<
  739.     for i := 1 to BookMarksCount do
  740.     begin
  741.       LbxBookMark.ItemIndex := i - 1;
  742.       LbxBookMark.Items.Add(ReadString('Path', 'Directory' +
  743.         IntToStr(i), ''));
  744.     end;
  745.     LastDirIndex := ReadInteger('General', 'LastDirIndex', -1);  //2.3
  746.     if (LastDirIndex = -1) and
  747.        (ReadString('Path', 'Directory1', '') <> '') then
  748.       LastDirIndex := 0;  //2.3
  749. //    LbxBookMark.ItemIndex := LastDirIndex;
  750.   finally
  751.     Free;
  752.   end;
  753.   LbxBookMark.ItemIndex := LastDirIndex;
  754. end; //LoadBookMarks
  755.  
  756. // Add current DirectoryListBox's directory to BookMark List
  757. procedure TPEMainForm.AddBookMkBtnClick(Sender: TObject);
  758. var
  759.   CurDir: string;
  760. begin
  761.   if SelectedPath = '' then //2.0
  762.   begin
  763.     MessageDlg('No Directory selected', mtError, [mbOK], 0);
  764.     exit;
  765.   end;
  766.   CurDir := AddSlash(SelectedPath); //2.0
  767.   if MessageDlg('Add the currently selected directory' + #13 +
  768.     '      "' + UpperCase(CurDir) + '"' + #13 +
  769.     'to the BookMarks List?' + #13, mtConfirmation,
  770.     [mbYes, mbNo], 0) = mrNo then
  771.     exit;
  772.   AddBookMark(CurDir);
  773. end; //AddBookMkBtnClick
  774.  
  775. // Add a Directory(NewDir) to BookMark List
  776. procedure TPEMainForm.AddBookMark(NewDir: string);
  777. begin
  778.   NewDir := LowerCase(NewDir);
  779.   LbxBookMark.Items.Add(NewDir);
  780.   LbxBookMark.ItemIndex := Pred(LbxBookMark.Items.Count);
  781.   IniFile := TIniFile.Create('LsPEPicture.ini');
  782.   with IniFile do
  783.   try
  784.     WriteInteger('General', 'BookMarksCount', LbxBookMark.Items.Count);
  785.     WriteString('Path', 'Directory' + IntToStr(LbxBookMark.Items.Count),
  786.       NewDir);
  787.   finally
  788.     Free;
  789.   end;
  790. end; //AddBookMark
  791.  
  792. // Delete selected BookMark from the BookMarks List
  793. procedure TPEMainForm.DelBookMkBtnClick(Sender: TObject);
  794. var
  795.   OldIndex: integer;
  796. begin
  797.   if (LbxBookMark.Items.Count = 0) or (LbxBookMark.ItemIndex = -1) or
  798.     (LbxBookMark.Visible = False) then
  799.   begin
  800.     MessageDlg('No Bookmark selected', mtError, [mbOK], 0);
  801.     exit;
  802.   end;
  803.   OldIndex := LbxBookMark.ItemIndex;
  804.   if MessageDlg('Are you sure you want to delete' + #13 + '    "' +
  805.     UpperCase(LbxBookMark.Items[OldIndex]) +
  806.     '"' + #13 + 'from the BookMarks List ?', mtConfirmation,
  807.     [mbYes, mbNo], 0) = mrYes then
  808.   try
  809.     LbxBookMark.Items.Delete(OldIndex);
  810.     LbxBookMark.ItemIndex := 0;
  811.     UpdateBookMarks;
  812.   finally
  813.     LbxBookMark.Visible := False;
  814.     LoadBookMarks;
  815.   end;
  816. end; //DelBookMkBtnClick
  817.  
  818. // Select a BookMark as DirectoryListBox1's Directory
  819. procedure TPEMainForm.LbxBookMarkDblClick(Sender: TObject);
  820. var
  821.   SelDir: string;
  822. begin
  823.   SelDir := LbxBookMark.Items[LbxBookMark.ItemIndex];
  824.   if DirectoryExists(SelDir) then
  825.   begin
  826.     SelectedPath := SelDir; //2.0
  827.     PathComboUpdate(SelDir); //2.0
  828.     FileViewBuildList(SelDir); //2.0
  829.     PageControl1.ActivePage := TabSheet1; //2.0
  830.     BookMkBtnClick(Sender);  //2.3
  831.   end else
  832.     MessageDlg('Selected Directory does not exist', mtInformation, [mbOK], 0);
  833.   LbxBookMark.Visible := False;
  834. end; //LbxBookMarkDblClick
  835.  
  836. { ========== Drag-n-Drop BookMarks in the BookMarks List ========== }
  837.  
  838. procedure TPEMainForm.LbxBookMarkDragOver(Sender, Source: TObject; X,
  839.   Y: Integer; State: TDragState; var Accept: Boolean);
  840. var
  841.   DropPos: Integer;
  842. begin
  843.   if Source = LbxBookMark then
  844.   begin
  845.     DropPos := LbxBookMark.ItemAtPos(Point(X, Y), False);
  846.     Accept := (DropPos > -1) and (DropPos < LbxBookMark.Items.Count);
  847.   end
  848.   else Accept := False;
  849. end; //LbxBookMarkDragOver
  850.  
  851. procedure TPEMainForm.LbxBookMarkDragDrop(Sender, Source: TObject; X,
  852.   Y: Integer);
  853. var
  854.   OldPos: Integer;
  855.   NewPos: Integer;
  856. begin
  857.   if Source = LbxBookMark then
  858.   begin
  859.     OldPos := LbxBookMark.ItemIndex;
  860.     NewPos := LbxBookMark.ItemAtPos(Point(X, Y), False);
  861.     if (NewPos > -1) and (NewPos <> OldPos) then
  862.       LbxBookMark.Items.Move(OldPos, NewPos);
  863.     UpdateBookMarks;
  864.     LbxBookMark.ItemIndex := NewPos;
  865.   end;
  866. end; //LbxBookMarkDragDrop
  867.  
  868. procedure TPEMainForm.LbxBookMarkMouseDown(Sender: TObject;
  869.   Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  870. var
  871.   DragItem: Integer;
  872. begin
  873.   if Button = mbLeft then
  874.   begin
  875.     DragItem := LbxBookMark.ItemAtPos(Point(X, Y), False);
  876.     if (DragItem > -1) and (DragItem < LbxBookMark.Items.Count) then
  877.       LbxBookMark.BeginDrag(False);
  878.   end
  879.   else if Button = mbRight then
  880.     LbxBookMark.Visible := False;
  881. end; //LbxBookMarkMouseDown
  882.  
  883. // Update IniFile (LsPEPicture.ini) after changing or deleting BookMarks
  884. procedure TPEMainForm.UpdateBookMarks;
  885. var
  886.   i: integer;
  887. begin
  888.   IniFile := TIniFile.Create('LsPEPicture.ini');
  889.   with IniFile do
  890.   try
  891.     WriteInteger('General', 'BookMarksCount', LbxBookMark.Items.Count);
  892.     EraseSection('Path');
  893.     LbxBookMark.ItemIndex := 0;
  894.     for i := 1 to LbxBookMark.Items.Count do begin
  895.       LbxBookMark.ItemIndex := i - 1;
  896.       WriteString('Path', 'Directory' + IntToStr(i),
  897.         LowerCase(LbxBookMark.Items[Pred(i)]));
  898.     end; // for
  899.   finally
  900.     Free;
  901.   end;
  902. end; //UpdateBookMarks
  903.  
  904.  
  905. { ==================== Convert Icons to Bitmaps =================== }
  906.  
  907. procedure TPEMainForm.ConvertBtnClick(Sender: TObject);
  908. var
  909.   Rect1: TRect;
  910.   Bmp1,
  911.     Bmp2: TBitmap;
  912. const
  913.   FExt = '.bmp';
  914. begin
  915.   Bmp1 := TBitmap.Create;
  916.   Bmp2 := TBitmap.Create;
  917.   Image4.Picture := nil;
  918.   SEdtWidth.Update;
  919.   SEdtHeight.Update;
  920.   if SEdtWidth.Value > 32 then
  921.     Panel8.Width := SEdtWidth.Value + 4;
  922.   if SEdtHeight.Value > 32 then
  923.     Panel8.Height := SEdtHeight.Value + 4;
  924.   if Icon1.Width > 32 then
  925.     Panel4.Width := Icon1.Width + 4;
  926.   if Icon1.Height > 32 then
  927.     Panel4.Height := Icon1.Height + 4;
  928.   with Rect1 do
  929.   begin
  930.     Top := 0;
  931.     Left := 0;
  932.     Right := SEdtWidth.Value;
  933.     Bottom := SEdtHeight.Value;
  934.   end;
  935.  
  936.   if Image3.Picture <> nil then
  937.   try
  938.     with Image3.Picture do
  939.     begin
  940.       Bmp1.Height := Icon.Height;
  941.       Bmp1.Width  := Icon.Width;
  942.       Bmp1.Canvas.Draw(0, 0, Icon);
  943.     end;
  944.  
  945.     if RBtn16C.Checked then
  946.       Bmp2.PixelFormat := pf4bit
  947.     else if RBtn256C.Checked then
  948.       Bmp2.PixelFormat := pf8bit
  949.     else if RBtnHiC.Checked then
  950.       Bmp2.PixelFormat := pf24bit;
  951.  
  952.     with Bmp2 do
  953.     begin
  954.       Width := SEdtWidth.Value;
  955.       Height := SEdtHeight.Value;
  956.       Canvas.StretchDraw(Rect1, Bmp1);
  957.     end;
  958.     Image4.Picture.Bitmap.Assign(Bmp2);
  959.     Image1.Picture.Bitmap.Assign(Bmp2);
  960.  
  961.     Label1.Caption :=
  962.       ChangeFileExt(ExtractFileName(FileView.Selected.SubItems[0]), FExt);
  963.     Caption := Title + '  -  ' + Label1.Caption;
  964.     Label3.Caption := Format('(%d x %d)', [Image1.Picture.Width,
  965.       Image1.Picture.Height]);
  966.     ConvertBtn.Enabled := False;
  967.   finally
  968.     Bmp1.Free;
  969.     Bmp2.Free;
  970.   end;
  971. end; //ConvertBtnClick
  972.  
  973. procedure TPEMainForm.CancelBtn2Click(Sender: TObject);
  974. begin
  975.   Image3.Picture := nil;
  976.   Image4.Picture := nil;
  977.   ResetTabSheet3; //2.1
  978.   RBtn256C.Checked := True; //2.1
  979. end;  //CancelBtn2Click
  980.  
  981. procedure TPEMainForm.ResetTabSheet3; //2.1 >>
  982. begin
  983.   Image3.Picture := nil;
  984.   Panel4.Height := 36;
  985.   Panel4.Width := 36;
  986.   Panel8.Height := 36;
  987.   Panel8.Width := 36;
  988.   SEdtHeight.Value := 32;
  989.   SEdtWidth.Value := 32;
  990. end;  //ResetTabSheet3  //2.1 <<
  991.  
  992. procedure TPEMainForm.RBtnClick(Sender: TObject); //2.1
  993. begin
  994.   Image3.Picture := nil;
  995. end;  //RBtnClick  //2.1
  996.  
  997.  
  998. { ================== PathCombo and FileView ======================= }
  999.  
  1000.  
  1001. procedure TPEMainForm.CreateImages; //2.0
  1002. var
  1003.   SysIL: UInt;
  1004.   SFI: TSHFileInfo;
  1005. begin
  1006.   sImages := TImageList.Create(self);
  1007.   SysIL := SHGetFileInfo('', 0, SFI, SizeOf(SFI), SHGFI_SYSICONINDEX
  1008.     or SHGFI_SMALLICON);
  1009.   if SysIL <> 0 then
  1010.   begin
  1011.     sImages.Handle := SysIL;
  1012.     sImages.ShareImages := True;
  1013.   end;
  1014.   FileView.SmallImages := sImages;
  1015. {**
  1016.   mySImgList := TImageList.Create(Self);
  1017.   mySImgList.Assign(sImages);
  1018.   SGoupBmp := TBitmap.Create;
  1019.   SGoupBmp.LoadFromResourceName(hInstance, 'Parent');
  1020.   SGoupIdx := mySImgList.Add(SGoupBmp, nil);
  1021.   mySImgList.ShareImages := False;
  1022.   FileView.SmallImages := mySImgList;
  1023. **}
  1024. end; //CreateImages
  1025.  
  1026. procedure TPEMainForm.PathComboUpdate(cPath: TFileName); //2.0
  1027. var
  1028.   Drv: byte;
  1029.   selDrv: byte;
  1030.   isDrive: boolean;
  1031.   i,
  1032.     cnt: integer;
  1033. begin
  1034.   SelPath := AddSlash(cPath);  //2.2
  1035.   with PEMainForm do
  1036.   begin
  1037.     PathCombo.items.beginupdate;
  1038.     PathCombo.items.clear;
  1039.     i := -1;
  1040.     isDrive := cPath = 'My Computer';
  1041.     selDrv := ord(upcase(cPath[1])) - ord('A');
  1042.     PathCombo.items.add('0:My Computer');
  1043.     for Drv := 0 to 25 do
  1044.       if Drv in drives then
  1045.       begin
  1046.         PathCombo.items.add('1:' + char(Drv + ord('A')) + ':\');
  1047.         if (not isDrive) and (Drv = selDrv) then
  1048.         begin
  1049.           for cnt := 1 to getcount('\', cPath) - 1 do
  1050.             PathCombo.items.add(IntToStr(cnt + 1) + ':'
  1051.               + copy(cPath, 1, numpos('\', cPath, cnt + 1)));
  1052.           i := PathCombo.items.count - 1;
  1053.         end;
  1054.         if isDrive then
  1055.           i := 0;
  1056.       end;
  1057. //    if i > -1 then                                     //2.2
  1058. //      PathCombo.items[i] := 'T' + PathCombo.items[i];  //2.2
  1059. //    PathCombo.itemindex := -1;                         //2.2
  1060.     PathCombo.items.endupdate;
  1061.     PathCombo.itemindex := i;
  1062.   end;
  1063. end; //PathComboUpdate
  1064.  
  1065. procedure TPEMainForm.PathComboChange(Sender: TObject); //2.0
  1066. var
  1067.   DirStr : string;
  1068. begin
  1069.   if PathCombo.droppeddown then exit;
  1070.   if PathCombo.itemindex <= 0 then exit;
  1071.   if PathCombo.itemindex = 0 then exit;
  1072.   DirStr := PathCombo.items[PathCombo.itemindex];
  1073.   DirStr := copy(DirStr, pos(':', DirStr) + 1, MaxInt);
  1074.   if (DirStr <> 'My Computer') and (not DirectoryExists(DirStr)) then
  1075.   begin
  1076.     MessageDlg('" ' + DirStr + ' "  is inaccessible !', mtInformation, [mbOK], 0);
  1077.     PathComboUpdate(SelPath);   //SelectedPath);  //2.2
  1078.     SelectedPath := SelPath;  //2.2
  1079.   end
  1080.   else begin
  1081.     SelectedPath := DirStr; //2.0
  1082.     PathComboUpdate(SelectedPath);
  1083.     FileViewBuildList(SelectedPath);
  1084.   end;
  1085. end; //PathComboChange
  1086.  
  1087. procedure TPEMainForm.PathComboDrawItem(Control: TWinControl;
  1088.   Index: Integer; Rect: TRect; State: TOwnerDrawState); //2.0
  1089. var
  1090.   DirName,
  1091.     DirStr: string;
  1092.   sfi: tshfileinfo;
  1093.   tab: integer;
  1094.   mode: integer;
  1095. begin
  1096.   fillchar(sfi, sizeof(tshfileinfo), 0);
  1097.   with PathCombo, PathCombo.canvas do
  1098.   begin
  1099.     Canvas.Font.Name := 'MS Sans Serif';
  1100.     Canvas.Font.Size := 8;
  1101.     mode := SHGFI_ICON or SHGFI_SMALLICON or SHGFI_DISPLAYNAME;
  1102.     DirStr := items[index];
  1103. //    if DirStr[1] = 'T' then           //2.2  >>
  1104. //    begin
  1105. //      DirStr := copy(DirStr, 2, maxint);
  1106. //      mode := mode or SHGFI_OPENICON;
  1107. //    end;                              //2.2 <<
  1108.     sImages.drawingstyle := dsTransparent;
  1109.     if odselected in state then
  1110.       sImages.drawingstyle := dsSelected;
  1111.     fillrect(rect);
  1112.     if DirStr = '0:My Computer' then
  1113.     begin
  1114.       sfi.szDisplayname := 'My Computer';
  1115.       sfi.iIcon := 15;
  1116.     end
  1117.     else
  1118.       SHGetFileInfo(pchar(copy(DirStr, pos(':', DirStr) + 1, maxint)), 0,
  1119.         sfi, sizeof(TSHFileInfo), mode);
  1120.     DirName := sfi.szDisplayName;
  1121.     tab := StrToInt(copy(DirStr, 1, pos(':', DirStr) - 1)) * 8;
  1122.  
  1123.     if not droppeddown then tab := 0;
  1124.  
  1125.     TextOut(Rect.Left + 20 + tab, Rect.Top + 2, DirName);
  1126.     sImages.draw(canvas, Rect.Left + 2 + tab, Rect.Top + 2, sfi.iIcon);
  1127.     sImages.drawingstyle := dsNormal;
  1128.   end;
  1129. end; //PathComboDrawItem
  1130.  
  1131. procedure TPEMainForm.PathComboClick(Sender: TObject); //2.0
  1132. begin
  1133.   with PathCombo do
  1134.   begin
  1135.     if ItemIndex = -1 then exit;
  1136.     if (ItemIndex = 0) then
  1137.       PathComboUpdate(SelectedPath)
  1138.     else begin
  1139.       SelectedPath := Items[ItemIndex];
  1140.       FileViewBuildList(SelectedPath);
  1141.     end;
  1142.   end;
  1143. end; //PathComboClick
  1144.  
  1145. procedure TPEMainForm.FileViewBuildList(cDir: string); //2.0
  1146. var
  1147.   CurDir,
  1148.     FName,
  1149.     FileName,
  1150.     FileOrDir: string;
  1151.   sfi: TSHFileInfo;
  1152.   hFindFile: THandle;
  1153.   Win32FD: TWin32FindData;
  1154.   OldCur: TCursor;
  1155. begin
  1156.   OldCur := Screen.Cursor;
  1157.   CurDir := AddSlash(cDir);
  1158.   hFindFile := FindFirstFile(PChar(CurDir + '*.*'), Win32FD);
  1159.   if hFindFile <> INVALID_HANDLE_VALUE then
  1160.   try
  1161.     Screen.Cursor := crHourGlass;
  1162.     FileView.Items.BeginUpdate;
  1163.     FileView.Items.Clear;
  1164.     repeat
  1165.       with Win32FD do
  1166.       begin
  1167.         if (dwFileAttributes and FILE_ATTRIBUTE_DIRECTORY > 0) then
  1168.           FileOrDir := 'dir'
  1169.         else
  1170.           FileOrDir := 'file';
  1171.  
  1172.         FName := StrPas(Win32FD.cFileName);
  1173.         FileName := CurDir + FName;
  1174.         if (FName = '.') then continue;
  1175.  
  1176.         SHGetFileInfo(PChar(FileName), 0, sfi, SizeOf(sfi),
  1177.           SHGFI_SYSICONINDEX or SHGFI_DISPLAYNAME);
  1178.  
  1179.         with FileView.Items.Add do
  1180.         begin
  1181.           if FName = '..' then
  1182.             Caption := ' ^Up 1 level'
  1183.           else
  1184.             Caption := FName;
  1185.           ImageIndex := sfi.iIcon;
  1186.           SubItems.Add(FileName);
  1187.           SubItems.Add(FileOrDir);
  1188.         end;
  1189.       end;
  1190.     until not FindNextFile(hFindFile, Win32FD);
  1191.   finally
  1192.     Windows.FindClose(hFindFile);
  1193.     FileView.Items.EndUpdate;
  1194.     Screen.Cursor := OldCur;
  1195.   end;
  1196. end; //FileViewBuildList
  1197.  
  1198. procedure TPEMainForm.FileViewCompare(Sender: TObject; Item1, Item2: TListItem;
  1199.   Data: Integer; var Compare: Integer); //2.0
  1200. var
  1201.   Caption1,
  1202.     Caption2: string;
  1203.   result: integer;
  1204. begin
  1205.   result := 0;
  1206.   if (Item1.SubItems[1] = 'dir') and (Item2.SubItems[1] <> 'dir') then
  1207.     Result := -1
  1208.   else if (Item1.SubItems[1] <> 'dir') and (Item2.SubItems[1] = 'dir') then
  1209.     Result := 1
  1210.   else
  1211.   begin
  1212.     Caption1 := AnsiUpperCase(Item1.Caption);
  1213.     Caption2 := AnsiUpperCase(Item2.Caption);
  1214.     if Caption1 > Caption2 then
  1215.       Result := 1
  1216.     else if Caption1 < Caption2 then
  1217.       Result := -1;
  1218.   end;
  1219.   Compare := Result;
  1220. end; //FileViewCompare
  1221.  
  1222. procedure TPEMainForm.FileViewDblClick(Sender: TObject); //2.0
  1223. var
  1224.   CurDir,
  1225.     NewDir: TFileName;
  1226. begin
  1227.   CurDir := '';
  1228.   NewDir := '';
  1229.   PageControl1.ActivePage := TabSheet1;
  1230.   with FileView do
  1231.   begin
  1232.     if (Selected <> nil) and (Selected.SubItems[1] = 'dir') then
  1233.     begin
  1234.       if Selected.Caption = ' ^Up 1 level' then
  1235.       begin
  1236.         CurDir := SelectedPath;
  1237.         CurDir := DelSlash(CurDir);
  1238.         NewDir := ExtractFilePath(CurDir);
  1239.       end
  1240.       else begin
  1241.         CurDir := Selected.SubItems[0];
  1242.         NewDir := AddSlash(CurDir);
  1243.       end;
  1244.       if NewDir <> '' then
  1245.       begin
  1246.         SelectedPath := NewDir;
  1247.         PathComboUpDate(SelectedPath);
  1248.         FileViewBuildList(SelectedPath);
  1249.       end
  1250.     end;
  1251.   end;
  1252. end; //FileViewDblClick
  1253.  
  1254. procedure TPEMainForm.FileViewClick(Sender: TObject); //2.0
  1255. var
  1256.   FileExt: string[4];
  1257. begin
  1258.   ClearBtnClick(Sender);
  1259.   PageControl1.ActivePage := TabSheet1;
  1260.   if FileView.Selected <> nil then //2.0
  1261.     SelectedFile := FileView.Selected.SubItems[0];
  1262.   FileExt := UpperCase(ExtractFileExt(SelectedFile));
  1263.  
  1264.   if (FileExt = '.BMP') or (FileExt = '.ICO') or
  1265.     (FileExt = '.WMF') then
  1266.   begin
  1267.     Image1.Picture.LoadFromFile(SelectedFile);
  1268.     Image2.Picture := Image1.Picture;
  1269.     Label1.Caption := ExtractFilename(SelectedFile);
  1270.     Caption := Title + '  -  ' + Label1.Caption;
  1271.  
  1272.     if (FileExt = '.BMP') then
  1273.     begin
  1274.       PageControl1.ActivePage := TabSheet1;
  1275.       Label3.Caption := Format('(%d x %d)', [Image1.Picture.Width,
  1276.         Image1.Picture.Height]);
  1277.       ViewAsGlyph(FileExt);
  1278.     end;
  1279.  
  1280.     if FileExt = '.ICO' then
  1281.     begin
  1282.       PageControl1.ActivePage := TabSheet3;
  1283.       Icon1 := Image1.Picture.Icon;
  1284.       Image3.Picture.Icon := Icon1;
  1285.       Image4.Picture := nil;
  1286.       ConvertBtn.Enabled := True;
  1287.     end;
  1288.  
  1289.     if FileExt = '.WMF' then
  1290.       PageControl1.ActivePage := TabSheet1;
  1291.   end;
  1292.   ReleaseBtn;
  1293. end;  //FileViewClick
  1294.  
  1295. procedure TPEMainForm.FileViewChange(Sender: TObject; Item: TListItem;
  1296.   Change: TItemChange); //2.0
  1297. var
  1298.   CurPath: string;
  1299. begin
  1300.   CurPath := AddSlash(SelectedPath);
  1301.   Image1.Picture.Graphic := nil;
  1302.   Image2.Picture.Graphic := nil;
  1303.   BitBtn1.Glyph := nil;
  1304.   Label1.Caption := '';
  1305.   Label3.Caption := '';
  1306.   Caption := Title;
  1307. end;  //FileViewChange
  1308.  
  1309. end.
  1310.  
  1311.