unit Kill_jc_f;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls,TLHelp32, TFlatButtonUnit, TFlatListBoxUnit, ExtCtrls;type
  TProcessInfo = Record
    ExeFile : String; //用来存放应用程序的文件名
    ProcessId : DWORD;//存放进程标识号
  end;
  ProcessInfo = ^TProcessInfo;
  TKill_jc = class(TForm)
    Label1: TLabel;
    FlatButton1: TFlatButton;
    FlatButton2: TFlatButton;
    FlatButton3: TFlatButton;
    ListBox1: TListBox;
    procedure ProcessList(var Plist:Tlist);
    procedure FormShow(Sender: TObject);
    procedure FlatButton1Click(Sender: TObject);
    procedure FlatButton3Click(Sender: TObject);
    procedure FlatButton2Click(Sender: TObject);
  private
    Current: TList;
    { Private declarations }
  public
    { Public declarations }
  end;var
  Kill_jc: TKill_jc;implementation{$R *.dfm}procedure TKill_jc.ProcessList(var PList:TList);
var p: ProcessInfo;
    ok: BOOL;
    ProcessListHandle: THandle;//进程列表的句柄
    ProcessStruct:TProcessEntry32;//进程的结构,进程的信息都在这个结构里
begin
  PList:=TList.Create;
  PList.Clear;
  ProcessListHandle:=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
  ProcessStruct.dwSize:=Sizeof(ProcessStruct);
  ok:=Process32First(ProcessListHandle,ProcessStruct);
  while ok do
  begin
    New(p);
    p.ExeFile:=ProcessStruct.szExeFile;
    p.ProcessId:=ProcessStruct.th32ProcessID;
    PList.Add(p);
    ok:=Process32Next(ProcessListHandle,ProcessStruct);
  end;
end;procedure TKill_jc.FormShow(Sender: TObject);
var i,MaxWidth:integer;
    P:ProcessInfo;
begin
  MaxWidth:=0;
  Current:=TList.Create;
  Current.Clear;
  ListBox1.Clear;
  ProcessList(Current);
  for i:=0 to Current.Count-1 do
    begin
      p:=Current.items[i];
      ListBox1.Items.Add(p.ExeFile);
      // 给ListBox1加底部滚动条
      if MaxWidth<ListBox1.Canvas.TextWidth(ListBox1.Items.Strings[i]) then
        MaxWidth:=ListBox1.Canvas.TextWidth(ListBox1.Items.Strings[i]);
    end;
  // 给ListBox1加底部滚动条
  if MaxWidth>=ListBox1.Width then
      SendMessage(ListBox1.Handle,LB_SETHORIZONTALEXTENT,MaxWidth+6,0);
end;procedure TKill_jc.FlatButton1Click(Sender: TObject);
var h:THandle;
    R:DWord;
    p:ProcessInfo;
begin
  R:=0;
  if ListBox1.ItemIndex >=0 then
  begin
    p:=Current.Items[ListBox1.ItemIndex];
    h:=OpenProcess(PROCESS_TERMINATE,True,P.ProcessID);
    if Integer(TerminateProcess(h,R))<>0 then
     begin
       CloseHandle(h);
       Current.Delete(ListBox1.ItemIndex);
       ListBox1.Items.Delete(ListBox1.ItemIndex);
     end;
  end
  else Application.MessageBox('你还没有选择进程,请先选择一个。','操作错误',MB_OK);
end;procedure TKill_jc.FlatButton3Click(Sender: TObject);
begin
  Close;
end;procedure TKill_jc.FlatButton2Click(Sender: TObject);
begin
  FormShow(Sender);
end;end.这是得到进程
如果要更多的,建议你去看看文档里有个“做一个自己的任务栏”
http://www.csdn.net/Develop/read_article.asp?id=14490

解决方案 »

  1.   

    unit stop;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, ComCtrls, StdCtrls, ExtCtrls, Buttons;type
      TForm1 = class(TForm)
        Panel1: TPanel;
        ListView1: TListView;
        Panel2: TPanel;
        SpeedButton1: TSpeedButton;
        Panel3: TPanel;
        SpeedButton2: TSpeedButton;
        Panel4: TPanel;
        SpeedButton3: TSpeedButton;
        procedure FormCreate(Sender: TObject);
        procedure ListView1ColumnClick(Sender: TObject; Column: TListColumn);
        procedure SpeedButton1Click(Sender: TObject);
        procedure SpeedButton2Click(Sender: TObject);
        procedure SpeedButton3Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
    var
            current:HWND;
            sz:array[0..254] of char;
    begin
            current:=GetWindow(handle,GW_HWNDFIRST);
            while current<>0 do
            begin
                    if GetWindowText(current,@sz,255)>0 then
                    listview1.Items.Add.Caption :=(strpas(@sz));
            current:=GetWindow(current,GW_HWNDNEXT);
            end;end;procedure TForm1.ListView1ColumnClick(Sender: TObject;
      Column: TListColumn);
    begin
    listview1.SortType :=sttext;
    end;procedure TForm1.SpeedButton1Click(Sender: TObject);
    var
            i:hwnd;
    begin
    i:=FindWindow(nil,PCHAR(listview1.Selected.Caption));
    Listview1.Selected.Delete ;
    if i<>0 then
            SendMessage(i,WM_CLOSE,0,0);end;procedure TForm1.SpeedButton2Click(Sender: TObject);
    var
            current:HWND;
            sz:array[0..254] of char;
    begin
            listview1.Clear;
            current:=GetWindow(handle,GW_HWNDFIRST);
            while current<>0 do
            begin
                    if GetWindowText(current,@sz,255)>0 then
                    listview1.Items.Add.Caption :=(strpas(@sz));
            current:=GetWindow(current,GW_HWNDNEXT);
            end;
    end;procedure TForm1.SpeedButton3Click(Sender: TObject);
    begin
    Close;
    end;end.