home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1998 April A / Pcwk4a98.iso / PROGRAM / DELPHI16 / Filepeek / PEEKUNIT.PAS < prev    next >
Pascal/Delphi Source File  |  1995-03-10  |  3KB  |  104 lines

  1. unit PeekUnit;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, ExtCtrls, StdCtrls, FileCtrl, MPlayer;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     LBHolder: TPanel;
  12.     FL: TFileListBox;
  13.     DL: TDirectoryListBox;
  14.     DCB: TDriveComboBox;
  15.     ImageHolder: TPanel;
  16.     Image: TImage;
  17.     MP: TMediaPlayer;
  18.     AVIPanel: TPanel;
  19.     procedure FLChange(Sender: TObject);
  20.     procedure FLDblClick(Sender: TObject);
  21.     procedure AVIPanelResize(Sender: TObject);
  22.     procedure FormResize(Sender: TObject);
  23.   private
  24.     { Private declarations }
  25.   public
  26.     { Public declarations }
  27.   end;
  28.  
  29. var
  30.   Form1: TForm1;
  31.  
  32. implementation
  33.  
  34. {$R *.DFM}
  35.  
  36. procedure TForm1.FLChange(Sender: TObject);
  37. begin
  38.   if FL.ItemIndex >= 0 then
  39.     begin
  40.       {Close the Media Player}
  41.       MP.Close;
  42.       {Only stretch metafiles}
  43.       Image.Stretch := (Pos('.wmf',FL.FileName) > 0);
  44.       if (Pos('.bmp',FL.FileName) > 0) or
  45.          (Pos('.wmf',FL.FileName) > 0) or
  46.          (Pos('.ico',FL.FileName) > 0) then
  47.          begin
  48.            Cursor := crHourglass;
  49.            Image.Picture.LoadFromFile(FL.FileName);
  50.            AVIPanel.Hide;
  51.            Image.Show;
  52.            Cursor := crDefault;
  53.          end;
  54.     end;
  55. end;
  56.  
  57. procedure TForm1.FLDblClick(Sender: TObject);
  58. begin
  59.   {If the user double-clicks on any WAV or AVI file, it will load and
  60.    activate the MediaPlayer control. AVI files are displayed on their own
  61.    area (AVIPanel). I selectively hide and show the AVIPanel and the Image
  62.    control based off of what is being displayed. This was because the
  63.    MediaPlayer needs a Panel to display on, and the BMP's, ICO's, and WMF's
  64.    needed an Image control to display on}
  65.   if (Pos('.wav',FL.FileName) > 0) or (Pos('.avi',FL.FileName) > 0) then
  66.     begin
  67.       Screen.Cursor := crHourglass;
  68.       MP.FileName := FL.FileName;
  69.       MP.Open;
  70.       if (Pos('.avi',FL.FileName) > 0) then
  71.         begin
  72.           Image.Hide;
  73.           AVIPanel.Show;
  74.           MP.Display := AVIPanel;
  75.           {I don't know why I have to shift the AVI panels display rect, but
  76.           it was off center if I didn't. Oh well, someone out there will be
  77.           able to explain it I am sure.}
  78.           With AVIPanel.BoundsRect do
  79.             MP.DisplayRect := Rect(Left-3,Top-3,Right-3,Bottom-3);
  80.         end;
  81.       Screen.Cursor := crDefault;
  82.       MP.Play;
  83.     end;
  84. end;
  85.  
  86. procedure TForm1.AVIPanelResize(Sender: TObject);
  87. begin
  88.   With AVIPanel.BoundsRect do
  89.     MP.DisplayRect := Rect(Left-3,Top-3,Right-3,Bottom-3);
  90. end;
  91.  
  92. procedure TForm1.FormResize(Sender: TObject);
  93. begin
  94.   {This procedure resizes the list boxes based off of the size of the main
  95.    form. This allows the listboxes to always be as large as they can}
  96.   MP.Top := Form1.ClientHeight-3-MP.Height;
  97.   DCB.Top := (Form1.ClientHeight-DCB.Height) div 2;
  98.   FL.Height := DCB.Top - 6;
  99.   DL.Top := DCB.Top + DCB.Height + 3;
  100.   DL.Height := Form1.ClientHeight - DL.Top - MP.Height - 6;
  101. end;
  102.  
  103. end.
  104.