home *** CD-ROM | disk | FTP | other *** search
/ Delphi 4 Bible / Delphi_4_Bible_Tom_Swan_IDG_Books_1998.iso / source / DIREXEC / MAIN.PAS < prev   
Pascal/Delphi Source File  |  1998-04-10  |  989b  |  47 lines

  1. unit Main;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, Windows, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, StdCtrls, Buttons, ShellAPI, DirDlg;
  8.  
  9. type
  10.   TMainForm = class(TForm)
  11.     RunBitBtn: TBitBtn;
  12.     BitBtn2: TBitBtn;
  13.     procedure RunBitBtnClick(Sender: TObject);
  14.   private
  15.     { Private declarations }
  16.   public
  17.     { Public declarations }
  18.   end;
  19.  
  20. var
  21.   MainForm: TMainForm;
  22.  
  23. implementation
  24.  
  25. {$R *.DFM}
  26.  
  27. function ExecuteFile(const FileName, Params, Dir: String;
  28.   ShowCmd: Integer): THandle;
  29. begin
  30.   Result := ShellExecute(Application.MainForm.Handle, nil,
  31.     PChar(FileName), PChar(Params), PChar(Dir), ShowCmd);
  32. end;
  33.  
  34. procedure TMainForm.RunBitBtnClick(Sender: TObject);
  35. begin
  36.   with DirDlgForm do
  37.   if ShowModal = mrOk then
  38.   if ExecuteFile(FileNameEdit.Text, '',
  39.     DirectoryListBox.Directory,SW_SHOW) <= 32 then
  40.     MessageDlg('Unable to open file or program',
  41.       mtError, [mbOk], 0)
  42.   else
  43.     Application.Minimize;
  44. end;
  45.  
  46. end.
  47.