home *** CD-ROM | disk | FTP | other *** search
- unit Unit1;
-
- interface
-
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- StdCtrls, ConsoleIO, Buttons, ExtCtrls, ComCtrls;
-
- type
- TForm1 = class(TForm)
- ListBox1: TListBox;
- Panel1: TPanel;
- Edit1: TEdit;
- GUI2Console1: TGUI2Console;
- procedure GUI2Console1Line(Sender: TObject; const Line: String);
- procedure GUI2Console1Done(Sender: TObject);
- procedure GUI2Console1Start(Sender: TObject; const Command: String);
- procedure FormCreate(Sender: TObject);
- procedure FormResize(Sender: TObject);
- procedure GUI2Console1PreDone(Sender: TObject);
- procedure GUI2Console1Prompt(Sender: TObject; const Line: String);
- procedure Edit1KeyPress(Sender: TObject; var Key: Char);
- procedure GUI2Console1Error(Sender: TObject; const Error: String);
- procedure Edit1KeyUp(Sender: TObject; var Key: Word;Shift: TShiftState);
- procedure ListBox1Enter(Sender: TObject);
-
- private
- { Private declarations }
- public
- { Public declarations }
- procedure WMEraseBkgnd(var Message : TWMEraseBkgnd); message WM_ERASEBKGnD;
- function AddListBox(const E : String): Integer;
- end;
-
- TPrompt = record
- Index : Integer;
- Str : String;
- end;
-
- var
- Form1: TForm1;
- Prompt : TPrompt;
- FKey : Char;
- Delimit : String; //Delimiter for cmd vs. command is different
-
- implementation
-
- {$R *.DFM}
-
- type
- TOSType = (ostUnknown,ostWin95,ostWinNT);
-
- function OSType : TOSType;
- var
- osv : TOSVersionInfo;
- begin
- osv.dwOSVersionInfoSize := sizeof(osv);
- GetVersionEx(osv);
- Case osv.dwPlatformId of
- VER_PLATFORM_WIN32_NT : Result := ostWinNT;
- VER_PLATFORM_WIN32_WINDOWS : Result := ostWin95;
- else Result := ostUnknown;
- end; //Case
- end;
-
- procedure TForm1.WMEraseBkgnd(var Message : TWMEraseBkgnd);
- begin
- Message.Result := 1;
- end;
-
-
- function TForm1.AddListBox(const E : String): integer;
- begin
- ListBox1.Items.BeginUpdate;
- while ListBox1.Items.Count > 150 do
- ListBox1.Items.Delete(0);
- Result := ListBox1.Items.Add(E);
- with ListBox1 do TopIndex := Items.Count-((Height div ItemHeight));
- ListBox1.Items.EndUpdate;
- end;
-
- procedure TForm1.GUI2Console1Line(Sender: TObject; const Line: String);
- begin
- If Line <> Prompt.Str then
- AddListBox(Line);
- Prompt.Str := '';
- end;
-
- procedure TForm1.GUI2Console1Done(Sender: TObject);
- begin
- AddListBox('Done...');
- end;
-
- procedure TForm1.GUI2Console1Start(Sender: TObject; const Command: String);
- begin
- AddListBox('Start...'+Command);
- end;
-
- procedure TForm1.FormCreate(Sender: TObject);
- begin
- Panel1.Height := Edit1.Height + 2;
- if OSType <> ostUnknown then
- begin
- Case OSType of
- ostWinNT : begin
- GUI2Console1.Application := 'c:\windows\system32\cmd.exe';
- GUI2Console1.Command := '';
- Delimit := CRLF;
- end;
- ostWin95 : begin
- GUI2Console1.Application := '';
- GUI2Console1.Command := 'command.com';
- Delimit := LF;
- GUI2Console1.AppType := at16bit;
- end;
- end;
- GUI2Console1.Start;
- end else
- begin
- AddListBox('Unknown OS Type');
- end;
- end;
-
- procedure TForm1.FormResize(Sender: TObject);
- begin
- Edit1.Width := Panel1.Width -2;
- ListBox1.TopIndex := ListBox1.Items.Count-1;
- end;
-
- procedure TForm1.GUI2Console1PreDone(Sender: TObject);
- begin
- GUI2Console1.Write(#4'C');
- GUI2Console1.WriteLn('exit');
- end;
-
- procedure TForm1.GUI2Console1Prompt(Sender: TObject; const Line: String);
- begin
- Prompt.Str := Line;
- Prompt.Index := AddListBox(Line);
- end;
-
- procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
- begin
- FKey := Key;
- end;
-
- procedure TForm1.GUI2Console1Error(Sender: TObject; const Error: String);
- begin
- AddListBox(Error);
- end;
-
- procedure TForm1.Edit1KeyUp(Sender: TObject; var Key: Word;
- Shift: TShiftState);
- begin
- if (FKey = #13) then
- begin
- GUI2Console1.Write(Edit1.Text+Delimit);
- Prompt.Str := Prompt.Str + Edit1.Text;
- Edit1.Text := '';
- FKey := #0;
- end else if Fkey in [#8,' '..'z']
- then
- begin
- ListBox1.Items.BeginUpdate;
- ListBox1.Items[Prompt.Index]:= Prompt.Str+ Edit1.Text;
- with ListBox1 do TopIndex := Items.Count-((Height div ItemHeight));
- ListBox1.Items.EndUpdate;
- end;
- end;
-
- procedure TForm1.ListBox1Enter(Sender: TObject);
- begin
- Edit1.Setfocus;
- end;
-
- end.
-