A程序利用ShellExecute調用B.exe和C.exe,那麼如何實現當A退出的時候B、C也同時關閉!!!

解决方案 »

  1.   

    procedure MCloseWindow(AClass, ACaption: string);
    var
      hPreWnd:HWND;
    begin
      hPreWnd:=FindWindow(PChar(AClass),PChar(ACaption));
      if hPreWnd<>0 then
        PostMessage(hPreWnd,WM_QUIT,0,0);
    end;//AClass是类名,ACaption是标题  MClossWindow('这是A程序的主窗口类名如TForm1','这是A程序的主窗口标题');
      

  2.   

    兄弟你还真吝啬var
    lppe:tprocessentry32;
    sshandle:thandle;
    hh:hwnd;
    found:boolean;
    begin
    sshandle:=createtoolhelp32snapshot(TH32CS_SNAPALL,0);
    found:=process32first(sshandle,lppe);
    while found do
    begin
      if uppercase(extractfilename(lppe.szExeFile))='PROJECT2.EXE' then
      begin
        hh:=OpenProcess(PROCESS_ALL_ACCESS,true,lppe.th32ProcessID);
        TerminateProcess(hh,0);
      end;
      found:=process32next(sshandle,lppe);
    end;
    end;
      

  3.   

    忘了说了,我那是假设要终止的程序的文件名为:project2.exe,你得改下判断条件
      

  4.   

    退出前找b、c的句柄,判断是否存在,如存在则发送wm_close消息,就可以关闭了