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

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