大悟还俗

邮箱 key_ok@qq.com 我的收集 http://pan.baidu.com/share/home?uk=1177427271
  新随笔  :: 联系 :: 订阅 订阅  :: 管理

模态运行EXE程序

Posted on 2013-10-09 11:35  大悟还俗_2  阅读(329)  评论(0编辑  收藏  举报
function ExecShowModal(APath: PChar; ACmdShow: Integer; ATimeout: Longword): Integer;
var
  vStartupInfo: TStartupInfo;
  vProcessInfo: TProcessInformation;
begin
  FillChar(vStartupInfo, SizeOf(TStartupInfo), 0);
  with vStartupInfo do
  begin
    cb := SizeOf(TStartupInfo);
    dwFlags := STARTF_USESHOWWINDOW or STARTF_FORCEONFEEDBACK;
    wShowWindow := ACmdShow;
  end;
  if CreateProcess(nil, APath, nil, nil, False,
    NORMAL_PRIORITY_CLASS, nil, nil,
    vStartupInfo, vProcessInfo) then
    Result := WaitForSingleObject(vProcessInfo.hProcess, ATimeout)
  else Result := GetLastError;
end;



procedure TForm1.Button3Click(Sender: TObject);
begin
  ExecShowModal('notepad.exe', SW_SHOW, INFINITE);
end;
View Code