|
|
#2
yeye552008-04-19 20:11
第一:为什么要用label?用Memo不是更好?
第二:对于内部命令要写成cmd /c dir *.*的格式,Win98是command /c dir *.*,因为内部命令没有对应的可执行文件。 核心代码如下: procedure TForm1.Button1Click(Sender: TObject); var SecurityAttributes : TSecurityAttributes; hProcess : TProcessInformation; StartupInfo : TStartupInfo; hReadPipe,hWritePipe : THandle; Buff : array [0..256] of char; Num : DWORD; dwExit:DWORD; SendName : String; s : String; begin SecurityAttributes.nLength:=Sizeof(SecurityAttributes); SecurityAttributes.lpSecurityDescriptor:=nil; SecurityAttributes.bInheritHandle:=true; CreatePipe(hReadPipe,hWritePipe,@SecurityAttributes,0); FillChar(StartupInfo,Sizeof(StartupInfo),#0); StartupInfo.cb:=Sizeof(StartupInfo); StartupInfo.dwFlags:=STARTF_USESHOWWINDOW or STARTF_USESTDHANDLES; StartupInfo.wShowWindow:=SW_HIDE; StartupInfo.hStdOutput:=hWritePipe; StartupInfo.hStdError:=hWritePipe; if CreateProcess(nil,PChar(self.Edit1.Text), @SecurityAttributes, @SecurityAttributes, true,0,nil,nil, StartupInfo, hProcess) then begin CloseHandle(hProcess.hThread); WaitForSingleObject(hProcess.hProcess,INFINITE); GetExitCodeProcess(hProcess.hProcess,dwExit); CloseHandle(hProcess.hProcess); CloseHandle(hWritePipe); Num:=0; s:=''; while ReadFile(hReadPipe,Buff,256,Num,nil) do begin Buff[Num]:=#0; s:=s+Buff; end; CloseHandle(hReadPipe); // self.Label1.Caption:=s; end else MessageBox(self.Handle,PChar('调用命令 '+self.Edit1.Text+' 失败!'),'调用失败',MB_OK or MB_ICONWARNING); end; |
我想在一个TEXT控件里输入dos命令 dir c\*.*. 然后按确定后,dos里显示的内容都转到label(标签)里显示,而不是在dos里显示..(界面上有TEXT、BUTTON、LABEL三个控件)
那位高手能帮帮忙写出一个完整的源代码吗?我看了几天网上介绍都看不懂,也不是我想要的结果.