home *** CD-ROM | disk | FTP | other *** search
- //---------------------------------------------------------------------------
- #include <vcl.h>
- #pragma hdrstop
-
- #include "Unit1.h"
- //---------------------------------------------------------------------------
- #pragma package(smart_init)
- #pragma link "ConsoleIO"
- #pragma link "ConsoleIO"
- #pragma resource "*.dfm"
- TForm1 *Form1;
- //---------------------------------------------------------------------------
- __fastcall TForm1::TForm1(TComponent* Owner)
- : TForm(Owner)
- {
- }
- //---------------------------------------------------------------------------
-
-
-
- TOSType OSType()
- {
- TOSVersionInfo osv;
- osv.dwOSVersionInfoSize = sizeof(osv);
- GetVersionEx(&osv);
- switch (osv.dwPlatformId)
- {
- case VER_PLATFORM_WIN32_NT : return(ostWinNT);
- case VER_PLATFORM_WIN32_WINDOWS : return(ostWin95);
- default : return(ostUnknown);
- }
- }
-
- int TForm1::AddListBox(AnsiString E)
- { int result;
- ListBox1->Items->BeginUpdate();
- while (ListBox1->Items->Count > 150)
- ListBox1->Items->Delete(0);
- result = ListBox1->Items->Add(E);
- ListBox1->TopIndex = ListBox1->Items->Count-((ListBox1->Height / ListBox1->ItemHeight));
- ListBox1->Items->EndUpdate();
- return(result);
- };
-
-
- void __fastcall TForm1::FormCreate(TObject *Sender)
- {
- Prompt.AtPrompt = false;
- Panel1->Height = Edit1->Height + 2;
- if (OSType() != ostUnknown)
- {
- switch (OSType())
- {
- case ostWinNT : {
- GUI2Console1->Application = "c:\\windows\\system32\\cmd.exe";
- GUI2Console1->Command = "";
- Delimit = CRLF;
- break;
- }
- case ostWin95 : {
- GUI2Console1->Application = "";
- GUI2Console1->Command = "command.com";
- Delimit = CR;
- GUI2Console1->AppType = at16bit;
- break;
- }
- }
- GUI2Console1->Start();
- } else AddListBox("Unknown OS Type");
-
- }
- //---------------------------------------------------------------------------
-
- void __fastcall TForm1::GUI2Console1Start(TObject *Sender,
- const AnsiString Command)
- {
- AddListBox("Start..."+Command);
- }
- //---------------------------------------------------------------------------
-
- void __fastcall TForm1::GUI2Console1Done(TObject *Sender)
- {
- AddListBox("Done...");
- }
- //---------------------------------------------------------------------------
-
- void __fastcall TForm1::GUI2Console1Line(TObject *Sender,const AnsiString Line)
- {
- if (Line != Prompt.Str)
- AddListBox(Line);
- Prompt.Str = "";
- Prompt.AtPrompt = false;
- }
- //---------------------------------------------------------------------------
-
- void __fastcall TForm1::FormResize(TObject *Sender)
- {
- Edit1->Width = Panel1->Width -2;
- ListBox1->TopIndex = ListBox1->Items->Count-1;
-
- }
- //---------------------------------------------------------------------------
-
- void __fastcall TForm1::GUI2Console1Prompt(TObject *Sender,
- const AnsiString Line)
- {
- Prompt.AtPrompt = true;
- Prompt.Str = Line;
- Prompt.Index = AddListBox(Line);
- }
- //---------------------------------------------------------------------------
-
- void __fastcall TForm1::Edit1KeyPress(TObject *Sender, char &Key)
- {
- FKey = Key;
- }
- //---------------------------------------------------------------------------
-
- void __fastcall TForm1::GUI2Console1Error(TObject *Sender,
- const AnsiString Error)
- {
- AddListBox(Error);
- }
- //---------------------------------------------------------------------------
-
- void __fastcall TForm1::ListBox1Enter(TObject *Sender)
- {
- Edit1->SetFocus();
- }
- //---------------------------------------------------------------------------
-
- void __fastcall TForm1::Edit1KeyUp(TObject *Sender, WORD &Key,
- TShiftState Shift)
- {
- switch (FKey)
- {
- case 3 : {
- GUI2Console1->Write(char(3));
- break;
- }
-
- case 13 : { GUI2Console1->Write(Edit1->Text + Delimit);
- Prompt.Str = Prompt.Str + Edit1->Text;
- Edit1->Text = "";
- FKey = 0;
- break;
- }
-
- default : if ((FKey == 8) || ((FKey >= ' ') & (FKey <= 'z' )))
- {
- if (ListBox1->Items->Count > 0)
- {
- ListBox1->Items->BeginUpdate();
- ListBox1->Items->Strings[Prompt.Index] = Prompt.Str + Edit1->Text;
- ListBox1->TopIndex = ListBox1->Items->Count-((ListBox1->Height / ListBox1->ItemHeight));
- ListBox1->Items->EndUpdate();
- }
- }
-
- } // End Switch
- }
- //---------------------------------------------------------------------------
-
- void __fastcall TForm1::GUI2Console1PreTerminate(TObject *Sender)
- {
- GUI2Console1->Write(char(3)+'C');
- GUI2Console1->WriteLN('exit');
-
- }
- //---------------------------------------------------------------------------
-
-