您的位置:首页 > 编程语言 > Delphi

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

2009-10-27 20:48 330 查看
我们经常能看到360安全卫士进行windows系统升级时,执行windows升级程序,当升级程序执行完成后,360马上弹出提示框。

这样的程序是如何做到的呢?下述代码就能完成!

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;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐