WinAPI里的WaitforSingleObject下面是我做的一个小例子,建立一个控制台程序,然后按下面的代码拷贝进去就能看到效果了,程序一直会等到'C:\WINDOWS\calc.exe'运行结束时才继续下去。program waitProc;
{$APPTYPE CONSOLE}
uses
SysUtils, ShellApi, Windows;var exePath : array[0..512] of char;
zCurDir:array[0..255] of char;
WorkDir:String;
StartupInfo:TStartupInfo;
ProcessInfo:TProcessInformation;begin
StrPCopy(exePath, 'C:\WINDOWS\calc.exe');
WorkDir := 'c:\';
StrPCopy(zCurDir, 'c:\');
FillChar(StartupInfo,Sizeof(StartupInfo),#0);
StartupInfo.cb := Sizeof(StartupInfo);
StartupInfo.dwFlags := STARTF_USESHOWWINDOW;
StartupInfo.wShowWindow := 1; if not CreateProcess(nil,
exePath,
nil,
nil,
false,
CREATE_NEW_CONSOLE or
NORMAL_PRIORITY_CLASS,
nil,
nil,
StartupInfo,
ProcessInfo) then
begin end else begin
WaitforSingleObject(ProcessInfo.hProcess,INFINITE);
shellexecute(0, nil, 'C:\WINDOWS\notepad.exe', nil, nil, 1);
end;
end.
{$APPTYPE CONSOLE}
uses
SysUtils, ShellApi, Windows;var exePath : array[0..512] of char;
zCurDir:array[0..255] of char;
WorkDir:String;
StartupInfo:TStartupInfo;
ProcessInfo:TProcessInformation;begin
StrPCopy(exePath, 'C:\WINDOWS\calc.exe');
WorkDir := 'c:\';
StrPCopy(zCurDir, 'c:\');
FillChar(StartupInfo,Sizeof(StartupInfo),#0);
StartupInfo.cb := Sizeof(StartupInfo);
StartupInfo.dwFlags := STARTF_USESHOWWINDOW;
StartupInfo.wShowWindow := 1; if not CreateProcess(nil,
exePath,
nil,
nil,
false,
CREATE_NEW_CONSOLE or
NORMAL_PRIORITY_CLASS,
nil,
nil,
StartupInfo,
ProcessInfo) then
begin end else begin
WaitforSingleObject(ProcessInfo.hProcess,INFINITE);
shellexecute(0, nil, 'C:\WINDOWS\notepad.exe', nil, nil, 1);
end;
end.
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货