JamesBond_L:你的代码我编译不过去,好多错误...<br>如果用WM_CLOSE的话,你得先得到外部程序的窗口句柄,如果你可以得到的话完全可以用.<br>不行的话,就用查找进程,然后结束的方法吧:<br>先引用Tlhelp32单元:<br>var:<br> ContinueLoop: BOOL;<br> FSnapshotHandle: THandle;<br> FProcessEntry32: TProcessEntry32;<br> result: integer;<br> strLExeFileName: string;<br>begin<br> strLExeFileName:='MyProgram.exe';<br> FSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);<br> FProcessEntry32.dwSize := Sizeof(FProcessEntry32);<br> ContinueLoop := Process32First(FSnapshotHandle, FProcessEntry32);<br> while integer(ContinueLoop) <> 0 do<br> begin<br> if ((UpperCase(ExtractFileName(FProcessEntry32.szExeFile)) = UpperCase(strLExeFileName))<br> or (UpperCase(FProcessEntry32.szExeFile) = UpperCase(strLExeFileName))) then<br> Result := Integer(TerminateProcess(OpenProcess(PROCESS_TERMINATE, BOOL(0), FProcessEntry32.th32ProcessID), 0));<br>end;