给分大放血!!!如何把控制台界面内嵌到我的程序窗口里???难吧???(100分)

  • 主题发起人 主题发起人 !雅龙
  • 开始时间 开始时间

!雅龙

Unregistered / Unconfirmed
GUEST, unregistred user!
[:D]如何把控制台界面内嵌到我的程序窗口里???难吧???[:D]
 
这个并不难,可以在Form上模拟一个吗!
由于WinNT、Win2000都已经彻底抛弃了DOS,而是全32位的,所以我们仔细观察一下WinNT和Win2000的
控制台界面,就会发现它本身就是在图形界面下模拟出来的,而不是以前DOS的字符界面。
比如:在Form上放一个Memo控件,将其字体设为Fixedsys,文字设为白色,背景颜色设为黑色,这不就
行了吗!至于程序的运行、显示,也都是模拟的,因为控制台程序不等于DOS程序。
 
to HD_COPY,能给出具体例子吗
 
参见下面的代码
procedure TMainForm.Button2Click(Sender: TObject);
var
 OutHandle:THandle;
 sinfo:_STARTUPINFOA;
 processinfo:_PROCESS_INFORMATION;
 CurFileName:string;
 ExitCode:Cardinal;
 nCount:integer;
begin
 CurFileName:=CurDir+'/temp.txt';
 //临时文件名


 //create the output file 's handle
  OutHandle:=CreateFile(pchar(CurFileName),GENERIC_WRITE,FILE_SHARE_WRITE,nil,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,0);

 //set the start information property
 sinfo.cb:=sizeof(sinfo);
 sinfo.lpReserved:=nil; //set all reserved property to the defined property
 sinfo.lpDesktop:=nil;
 sinfo.lpTitle:=nil;
 sinfo.dwFlags:=STARTF_USESHOWWINDOW or STARTF_USESTDHANDLES ;
 sinfo.wShowWindow:=SW_HIDE;
 sinfo.cbReserved2:=0;
 sinfo.lpReserved2:=nil;
 sinfo.hStdOutput:=OutHandle;//set the output handle
 sinfo.hStdInput:=STD_INPUT_HANDLE ;//set to default
 sinfo.hStdError:=STD_ERROR_HANDLE ;

 if not(CreateProcess(nil,pchar(Edit1.Text),nil,nil,true,CREATE_NEW_CONSOLE,nil,nil,sinfo,processinfo))
 then
  begin
   ShowMessage('Process can not be created');
   CloseHandle(OutHandle);
  end;

 nCount:=0;
 //set the time out

 //wait for process stop
 while (GetExitCodeProcess(processinfo.hProcess,ExitCode))and(ExitCode=STILL_ACTIVE)and(nCount<MaxCount) do
 begin
  Sleep(500);
  inc(nCount);
 end;

 if not(GetExitCodeProcess(processinfo.hProcess,ExitCode)) or (ExitCode=STILL_ACTIVE)
 then //time out , mannualy close process
  TerminateProcess(processinfo.hProcess,0); 

 CloseHandle(OutHandle);

 //load the output to the memo
 memo1.Lines.LoadFromFile(CurFileName);


end;
用相同的方法就可以解决你的问题,具体的文章请看这里:
http://go7.163.com/zeroworld/program/process.html

在该文中使用了文件流,可以直接使用内存流,那样就更好了。
 
接受答案了.
 
后退
顶部