检查窗口类名或者窗口名,可以放在一个timer事件里 假设APPNAME为调用的程序主窗口的类名 hHandle:=FindWindow(APPNAME,nil); if hHandle>0 then begin //运行中 end else begin //已经关闭 end;假设APPNAME为调用的程序主窗口的窗口 hHandle:=FindWindow(nil,APPNAME); if hHandle>0 then begin //运行中 end else begin //已经关闭 end;
假设APPNAME为调用的程序主窗口的类名
hHandle:=FindWindow(APPNAME,nil);
if hHandle>0 then
begin
//运行中
end
else
begin
//已经关闭 end;假设APPNAME为调用的程序主窗口的窗口
hHandle:=FindWindow(nil,APPNAME);
if hHandle>0 then
begin
//运行中
end
else
begin
//已经关闭 end;
function WinExecAndWait32(CommandLine: string; Visibility: Integer): Cardinal;
var
WorkDir: string;
StartupInfo: TStartupInfo;
ProcessInfo: TProcessInformation;
begin
{应用程序的工作目录}
WorkDir := ExtractFileDir(Application.ExeName);
FillChar(StartupInfo, Sizeof(StartupInfo), #0);
StartupInfo.cb := Sizeof(StartupInfo);
{设置进程显示标志}
StartupInfo.dwFlags := STARTF_USESHOWWINDOW;
StartupInfo.wShowWindow := Visibility;
{创建进程,执行该文件}
if not CreateProcess(nil,
PChar(CommandLine), {指向命令行字符串}
nil, {指向进程安全属性}
nil, {指向线程安全属性}
True, {句柄继承标志}
CREATE_NEW_CONSOLE or {创建标志}
NORMAL_PRIORITY_CLASS,
nil, {指向环境块}
PChar(WorkDir), {指向当前目录}
StartupInfo, {指向结构STARTUPINFO }
ProcessInfo) {指向结构PROCESS_INFO }
then Result := INFINITE {-1} else
begin
FormPassDialog.Hide;{隐藏输入密码的窗口}
{防止拷贝该临时文件}
FormPassDialog.iTempFileName := FileOpen(FormPassDialog.TempFileName, fmShareExclusive);
{设置应用程序的风格}
SetWindowLong(Application.Handle, GWL_EXSTYLE, WS_EX_TOOLWINDOW);
{提交系统控制权}
Application.ProcessMessages;
{等待刚才创建的进程运行结束}
WaitforSingleObject(ProcessInfo.hProcess, INFINITE);
{获取进程的退出代码}
GetExitCodeProcess(ProcessInfo.hProcess, Result);
{关闭进程}
CloseHandle(ProcessInfo.hProcess);
{关闭进程}
CloseHandle(ProcessInfo.hThread);
{退出本应用程序}
FormPassDialog.Close;
end;
end;
而后调用waitforsingleobject(句柄,....)