home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1998 April A / Pcwk4a98.iso / PROGRAM / DELPHI16 / Calmira / Src / SRC / RUNPROG.PAS < prev    next >
Pascal/Delphi Source File  |  1997-02-15  |  4KB  |  136 lines

  1. {**************************************************************************}
  2. {                                                                          }
  3. {    Calmira shell for Microsoft« Windows(TM) 3.1                          }
  4. {    Source Release 1.0                                                    }
  5. {    Copyright (C) 1997  Li-Hsin Huang                                     }
  6. {                                                                          }
  7. {    This program is free software; you can redistribute it and/or modify  }
  8. {    it under the terms of the GNU General Public License as published by  }
  9. {    the Free Software Foundation; either version 2 of the License, or     }
  10. {    (at your option) any later version.                                   }
  11. {                                                                          }
  12. {    This program is distributed in the hope that it will be useful,       }
  13. {    but WITHOUT ANY WARRANTY; without even the implied warranty of        }
  14. {    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         }
  15. {    GNU General Public License for more details.                          }
  16. {                                                                          }
  17. {    You should have received a copy of the GNU General Public License     }
  18. {    along with this program; if not, write to the Free Software           }
  19. {    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.             }
  20. {                                                                          }
  21. {**************************************************************************}
  22.  
  23. unit Runprog;
  24.  
  25. interface
  26.  
  27. uses Classes, Forms, Controls, Buttons, StdCtrls, Dialogs;
  28.  
  29. type
  30.   TRunDlg = class(TForm)
  31.     OKBtn: TBitBtn;
  32.     CancelBtn: TBitBtn;
  33.     Label1: TLabel;
  34.     Combo: TComboBox;
  35.     RunMin: TCheckBox;
  36.     DosCommand: TCheckBox;
  37.     OpenDialog: TOpenDialog;
  38.     BrowseBtn: TBitBtn;
  39.     procedure OKBtnClick(Sender: TObject);
  40.     procedure FormCreate(Sender: TObject);
  41.     procedure FormClose(Sender: TObject; var Action: TCloseAction);
  42.     procedure FormDestroy(Sender: TObject);
  43.     procedure CancelBtnClick(Sender: TObject);
  44.     procedure BrowseBtnClick(Sender: TObject);
  45.     procedure FormPaint(Sender: TObject);
  46.   private
  47.     { Private declarations }
  48.     Changed : Boolean;
  49.   public
  50.     { Public declarations }
  51.   end;
  52.  
  53. procedure RunExecute(const s: string);
  54.  
  55. implementation
  56.  
  57. {$R *.DFM}
  58.  
  59. uses SysUtils, Files, Settings, WinProcs, WinTypes, MiscUtil,
  60.   Resource, Environs;
  61.  
  62. var RunDlg: TRunDlg;
  63.  
  64. procedure RunExecute(const s: string);
  65. begin
  66.   if RunDlg = nil then RunDlg := TRunDlg.Create(Application);
  67.  
  68.   with RunDlg do begin
  69.     Combo.Text := s;
  70.     WindowState := wsNormal;
  71.     Show;
  72.   end;
  73. end;
  74.  
  75.  
  76. procedure TRunDlg.OKBtnClick(Sender: TObject);
  77. const
  78.   Commands: array[Boolean] of Word = (SW_SHOW, SW_SHOWMINNOACTIVE);
  79. var
  80.   command: array[0..79] of Char;
  81. begin
  82.   Changed := AddHistory(Combo) or Changed;
  83.   with Combo do
  84.     if Text > '' then begin
  85.       if DosCommand.Checked then
  86.         WinExec(StrPCopy(@command,
  87.           EnvironSubst('%COMSPEC% /c ' + Text)), Commands[RunMin.Checked])
  88.       else
  89.         WinExec(StrPCopy(@command, Text), Commands[RunMin.Checked]);
  90.     end;
  91. end;
  92.  
  93.  
  94. procedure TRunDlg.FormCreate(Sender: TObject);
  95. begin
  96.   Icon.Assign(Icons.Get('RunDialog'));
  97.   ini.ReadStrings('RunProgram', Combo.Items);
  98. end;
  99.  
  100.  
  101. procedure TRunDlg.FormClose(Sender: TObject; var Action: TCloseAction);
  102. begin
  103.   Action := caFree;
  104. end;
  105.  
  106.  
  107. procedure TRunDlg.FormDestroy(Sender: TObject);
  108. begin
  109.   if Changed then begin
  110.     ini.EraseSection('RunProgram');
  111.     ini.WriteStrings('RunProgram', Combo.Items);
  112.   end;
  113.   RunDlg := nil;
  114. end;
  115.  
  116.  
  117. procedure TRunDlg.CancelBtnClick(Sender: TObject);
  118. begin
  119.   Close;
  120. end;
  121.  
  122.  
  123. procedure TRunDlg.BrowseBtnClick(Sender: TObject);
  124. begin
  125.   if OpenDialog.Execute then
  126.     Combo.Text := Lowercase(OpenDialog.Filename);
  127. end;
  128.  
  129.  
  130. procedure TRunDlg.FormPaint(Sender: TObject);
  131. begin
  132.   Border3D(Canvas, ClientWidth-1, ClientHeight-1);
  133. end;
  134.  
  135. end.
  136.