救急 用DELPHI 程序外部调用 exe 时 ,在外部EXE运行完成后才继续执行(70分)

  • 主题发起人 主题发起人 ldxcd_77
  • 开始时间 开始时间
L

ldxcd_77

Unregistered / Unconfirmed
GUEST, unregistred user!
各位大虾!
比如
winexe('clock.exe',0); ----》1
showmessage('aaaaaaaa'); ----》2

怎样实现 让clock.exe 程序被关闭以后 才执行 2行的代码?
HELP ! help!


 
var
sCommandLine: string;
bCreateProcess: boolean;
lpStartupInfo: TStartupInfo;
lpProcessInformation: TProcessInformation;
begin
sCommandLine := 'ARJ.EXE /?';
bCreateProcess := CreateProcessA(nil, PChar(sCommandLine),
nil, nil, True, NORMAL_PRIORITY_CLASS, nil, nil,
lpStartupInfo, lpProcessInformation);
if bCreateProcess then
WaitForSingleObject(lpProcessInformation.hProcess, INFINITE);
end;
//////////////////////////////////////////////
var
pWindowsList: pointer;
hActiveWindow: HWnd;
hExeHandle: THandle;
begin
pWindowsList := DisableTaskWindows(0);
hActiveWindow := GetActiveWindow;
try
hExeHandle := WinExec('arj.exe /?',SW_SHOWNORMAL);
while GetModuleUsage(hExeHandle) <> 0 do
Application.ProcessMessages;
finally
EnableTaskWindows(pWindowsList);
SetActiveWindow(hActiveWindow);
end;
end;
 
sherman 能否说清楚一些
我使用代码好象不行
没有 GETMODULEUSAGE() 函数
 
你找一下,原来的贴子中有,这是我改成C语言版的。

WORD WinExecAndWait32(String FileName,int Visibility )
{
LPSTARTUPINFO StartupInfo;
LPPROCESS_INFORMATION ProcessInfo;


//GETDIR(0,WorkDir);
//StrPCopy(zCurDir,WorkDir);
//Fillchar(StartupInfo,Sizeof(StartupInfo),#0);
StartupInfo->cb = sizeof(StartupInfo);
StartupInfo->dwFlags = STARTF_USESHOWWINDOW;
StartupInfo->wShowWindow = Visibility;

if (! CreateProcess(NULL,
FileName.c_str(), //{ pointer to command line string }
NULL, //{ pointer to process security attributes }
NULL, //{ pointer to thread security attributes }
false, //{ handle inheritance flag }
CREATE_NEW_CONSOLE | //{ creation flags }
NORMAL_PRIORITY_CLASS,
NULL, //{ pointer to new environment block }
NULL, //{ pointer to current directory name }
StartupInfo, //{ pointer to STARTUPINFO }
ProcessInfo))
return -1; //{ pointer to PROCESS_INF }
else {
WaitForSingleObject(ProcessInfo->hProcess,INFINITE);
LPDWORD Result;
GetExitCodeProcess(ProcessInfo->hProcess,Result);
return *Result;
}
 
多人接受答案了。
 
后退
顶部