请问主程序用WINEXEC调用一个EXE程序,如何在主程序退出时,也自动关闭被调用的EXE程序?(50分)

  • 主题发起人 主题发起人 xcs_2001
  • 开始时间 开始时间
X

xcs_2001

Unregistered / Unconfirmed
GUEST, unregistred user!
请问主程序用WINEXEC调用一个EXE程序,如何在主程序退出时,也自动关闭被调用的EXE程序?
 
很难做到!用ShellExecute好点!
 
请教用ShellExecute,如何做?
 
用WM_CLOSE试试
 
...<br>var<br>ShExecInfo:SHELLEXECUTEINFO ;<br>begin<br>ShExecInfo.cbSize := sizeof(SHELLEXECUTEINFO);<br>ShExecInfo.fMask := SEE_MASK_NOCLOSEPROCESS;<br>ShExecInfo.hwnd := nil;<br>ShExecInfo.lpVerb := nil;<br>ShExecInfo.lpFile := "c:/MyProgram.exe"; <br>ShExecInfo.lpParameters := ""; <br>ShExecInfo.lpDirectory := nil;<br>ShExecInfo.nShow := SW_SHOW;<br>ShExecInfo.hInstApp := nil; <br>ShellExecuteEx(&amp;ShExecInfo);<br>WaitForSingleObject(ShExecInfo.hProcess,INFINITE);<br>close;<br>end;
 
JamesBond_L:你的代码我编译不过去,好多错误...<br>如果用WM_CLOSE的话,你得先得到外部程序的窗口句柄,如果你可以得到的话完全可以用.<br>不行的话,就用查找进程,然后结束的方法吧:<br>先引用Tlhelp32单元:<br>var:<br>&nbsp; ContinueLoop: BOOL;<br>&nbsp; FSnapshotHandle: THandle;<br>&nbsp; FProcessEntry32: TProcessEntry32;<br>&nbsp; result: integer;<br>&nbsp; strLExeFileName: string;<br>begin<br>&nbsp; strLExeFileName:='MyProgram.exe';<br>&nbsp; &nbsp; FSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);<br>&nbsp; &nbsp; FProcessEntry32.dwSize := Sizeof(FProcessEntry32);<br>&nbsp; &nbsp; ContinueLoop := Process32First(FSnapshotHandle, FProcessEntry32);<br>&nbsp; &nbsp; while integer(ContinueLoop) &lt;&gt; 0 do<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; if ((UpperCase(ExtractFileName(FProcessEntry32.szExeFile)) = UpperCase(strLExeFileName))<br>&nbsp; &nbsp; &nbsp; &nbsp; or (UpperCase(FProcessEntry32.szExeFile) = UpperCase(strLExeFileName))) then<br>&nbsp; &nbsp; &nbsp; &nbsp; Result := Integer(TerminateProcess(OpenProcess(PROCESS_TERMINATE, BOOL(0), FProcessEntry32.th32ProcessID), 0));<br>end;
 
你可以用别的方法完成同样的功能<br>用OpenFile 试试
 
后退
顶部