码迷,mamicode.com
首页 > Windows程序 > 详细

delphi执行一个外部程序,当外部程序结束后,delphi程序立即响应

时间:2016-10-07 14:03:51      阅读:308      评论:0      收藏:0      [点我收藏+]

标签:

//需要引用 ShellAPI 单元;
procedure TForm1.Button1Click(Sender: TObject); var SEInfo: TShellExecuteInfo; ExitCode: DWORD; ExecuteFile, ParamString, StartInString: string; begin ExecuteFile := ‘c:\Windows\system32\Calc.exe‘; FillChar(SEInfo, SizeOf(SEInfo), #0); SEInfo.cbSize := SizeOf(TShellExecuteInfo); with SEInfo do begin fMask := SEE_MASK_NOCLOSEPROCESS; Wnd := Application.Handle; lpFile := PChar(ExecuteFile); //ParamString can contain the application parameters // lpParameters := PChar(ParamString); //StartInString specifies the name of the working directory.if ommited, the current directory is used. // lpDirectory := PChar(StartInString); nShow := SW_SHOWNORMAL; end; if ShellExecuteEx(@SEInfo) then begin repeat Application.ProcessMessages; GetExitCodeProcess(SEInfo.hProcess, ExitCode); if ExitCode = STILL_ACTIVE then Sleep(500); until (ExitCode <> STILL_ACTIVE) or Application.Terminated; ShowMessage(‘Calculator terminated‘); end else ShowMessage(‘Error starting Calc!‘); end;

delphi执行一个外部程序,当外部程序结束后,delphi程序立即响应

标签:

原文地址:http://www.cnblogs.com/westsoft/p/5935803.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!