各位好!我找到一段程序,是在listbox中显示出进程和进程ID,请教如何点击listbox,从而关闭其中一个进程?请给参考程序,非常谢谢!
源程序:
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls,Tlhelp32;type
TForm1 = class(TForm)
Button1: TButton;
ListBox1: TListBox;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
proid:DWORD;
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.DFM}procedure TForm1.Button1Click(Sender: TObject);
var
FSnapshotHandle:THandle;
FProcessEntry32:TProcessEntry32;
Ret:BOOL;
ProcessID:integer;
ProcessHndle:THandle;
begin
FSnapshotHandle:=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
FProcessEntry32.dwSize:=Sizeof(FProcessEntry32);
Ret:=Process32First(FSnapshotHandle,FProcessEntry32);
while Ret do
begin
ProcessID:=FProcessEntry32.th32ProcessID;
ListBox1.Items.Add(FProcessEntry32.szExeFile+' '+IntToHex(FProcessEntry32.th32ProcessID,8));
ret:=Process32Next(FSnapshotHandle,FProcessEntry32);
end;
end;
end.
源程序:
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls,Tlhelp32;type
TForm1 = class(TForm)
Button1: TButton;
ListBox1: TListBox;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
proid:DWORD;
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.DFM}procedure TForm1.Button1Click(Sender: TObject);
var
FSnapshotHandle:THandle;
FProcessEntry32:TProcessEntry32;
Ret:BOOL;
ProcessID:integer;
ProcessHndle:THandle;
begin
FSnapshotHandle:=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
FProcessEntry32.dwSize:=Sizeof(FProcessEntry32);
Ret:=Process32First(FSnapshotHandle,FProcessEntry32);
while Ret do
begin
ProcessID:=FProcessEntry32.th32ProcessID;
ListBox1.Items.Add(FProcessEntry32.szExeFile+' '+IntToHex(FProcessEntry32.th32ProcessID,8));
ret:=Process32Next(FSnapshotHandle,FProcessEntry32);
end;
end;
end.
解决方案 »
- dbgrideh如何在里面输入数据?
- delphi+mysql读取中文问题 在线等
- 【急】关于webbrowser的问题,各位大侠进来指教下,谢谢!!!
- 乱码 DbgridEH导出Excel时中文字会显示乱码,请问有什么解决方法?
- Delphi 类的问题
- 在Delph中如何调用选文件档的对话框?
- 高手指点,我想把listview中的数据导入到EXCEL可以吗?具体怎么做?主要我不知道怎样按顺序获得listview中的数据。
- 你说我象雨,忽远忽近,其实你不懂我的心。。。。。。。。。。。。。。
- 真诚请教数据库图像问题
- 怎样用api设置PageControl的Multiline属性?
- 四行语句,有一条有错误,高手看一下。。
- 不明白!?求救,我用纪录模拟C++中的远程结构体指针...(在线等)
var
hprocessID: INTEGER;
processHandle: THandle;
DWResult: DWORD;
begin
SendMessageTimeout(hWindowHandle, WM_CLOSE, 0, 0,
SMTO_ABORTIFHUNG or SMTO_NORMAL, 5000, DWResult); if isWindow(hWindowHandle) then
begin
// PostMessage(hWindowHandle, WM_QUIT, 0, 0); { Get the process identifier for the window}
GetWindowThreadProcessID(hWindowHandle, @hprocessID);
if hprocessID <> 0 then
begin
{ Get the process handle }
processHandle := OpenProcess(PROCESS_TERMINATE or PROCESS_QUERY_INFORMATION,
False, hprocessID);
if processHandle <> 0 then
begin
{ Terminate the process }
TerminateProcess(processHandle, 0);
CloseHandle(ProcessHandle);
end;
end;
end;
end; procedure TForm1.Button2Click(Sender: TObject);
begin
KillProcess(FindWindow('notepad',nil));
end;