在调试的时候,当关闭了所有窗口以后,发现 该应用程序还在 “任务管理”器的进程 里面,有什么方法可以实现关掉所有进程啊

解决方案 »

  1.   

    关闭进程的代码,注意有些系统进程是不能的。
    //转代码uses tlhelp32;procedure TForm1.Button2Click(Sender: TObject);
    var
      hSnapshot: Integer;
      bFound: Boolean;
      ProcessEntry: ProcessEntry32;
    begin
      hSnapshot := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
      if hSnapshot = 0 then Exit;
      bFound := Process32First(hSnapshot, ProcessEntry);
      while bFound do
      begin
        if LowerCase(ExtractFileExt(ProcessEntry.szExeFile)) = '.exe' then
          with ListView1.Items.Add do
          begin
            Caption := ProcessEntry.szExeFile;
            SubItems.Add(IntToStr(ProcessEntry.th32ProcessID));
          end;
        bFound := Process32Next(hSnapshot, ProcessEntry);
      end;
      CloseHandle(hSnapshot);
    end;procedure TForm1.Button3Click(Sender: TObject);
    var
      iProcessId: Integer;
      hProcess: Integer;
    begin
      if ListView1.Selected <> nil then
      begin
        iProcessId := StrToInt(ListView1.Selected.SubItems[0]);
        hProcess := OpenProcess(PROCESS_ALL_ACCESS, false, iProcessId);
        if hProcess <> 0 then
          TerminateProcess(hProcess, 0);
      end;
    end;
      

  2.   

    一般你退出的时候使用Application.Terminate就能关闭
      

  3.   

    非注窗体close只能将窗体关掉
    需要用Application.Terminate才能将 主程序关掉