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
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
解决方案 »
- 给CXGrid的popupmenu赋值时发生错误?这是怎么回事啊?
- demo《使用SQL DMO导出建表语句和插入语句》的问题
- QRLABEL或者QRMEMO怎么实现自动换行
- 新手问题:
- 在Canvas上绘制一个可移动的类似AutoCad标靶的方框。Canvas上的内容不得删除。
- 怎么判断系统安装在那个目录下(比如:c:\windows或是d:\winnt),谢谢
- 什么是3721病毒
- 请问如何用DBEDIT显示被查询出来的某一记录的某一字段?谢了!
- dephi真的牛吗?
- 提问:怎样拦截整个windows的消息,不单是发给应用程序的
- 谁有这个问题上的代码?http://www.csdn.net/expert/topic/836/836925.xml?temp=.4008142
- tangss进来领分!
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.