-
Notifications
You must be signed in to change notification settings - Fork 2
/
ProcessListForm.pas
114 lines (100 loc) · 2.45 KB
/
ProcessListForm.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
unit ProcessListForm;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, UList, ProcList, Controls, Forms,
Dialogs, StdCtrls, ComCtrls, Menus ;
type
TProcListForm = class(TForm)
ListView1: TListView;
Button1: TButton;
Button2: TButton;
PopupMenu1: TPopupMenu;
Kill1: TMenuItem;
procedure FormShow(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure Kill1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure ListView1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
private
{ Private declarations }
public
{ Public declarations }
end;
var
ProcListForm: TProcListForm;
implementation
{$R *.dfm}
procedure TProcListForm.FormShow(Sender: TObject);
var
List: PListStruct;
Process: PProcessRecord;
Path: string;
begin
ListView1.DoubleBuffered := true;
List := nil;
GetFullProcessesInfo(List);
ListView1.Items.Clear;
while List <> nil do
begin
with ListView1.Items.Add do
begin
Process := List^.pData;
Caption := Process^.ProcessName;
SubItems.Append(IntToStr(Process^.ProcessId));
Path := Process^.Path;
System.Delete(Path, 1, Pos(':', Path) - 2);
//Path[1] := UpperCase(Path[1])[1];
SubItems.Append(Path);
end;
List := List^.pNext;
end;
FreeListWidthData(List);
Self.Resize;
end;
procedure TProcListForm.FormActivate(Sender: TObject);
begin
ShowWindow(Application.Handle, SW_HIDE);
Application.BringToFront;
end;
procedure TProcListForm.Kill1Click(Sender: TObject);
var
Item: TListItem;
hProcess: integer;
Result: Boolean;
begin
Result := False;
Item := ListView1.Selected;
if Item <> nil then
begin
hProcess := OpenProcess(PROCESS_TERMINATE, false, StrToInt(Item.SubItems.Strings[0]));
if hProcess > 0 then
begin
Result := TerminateProcess(hProcess, 0);
CloseHandle(hProcess);
end
else
Result := False;
end;
if Result = True then
ListView1.Selected.Delete
else
MessageDlg('Íå óäàëîñü çàâåðøèòü ïðîöåññ', mtWarning, [mbOk], 0);
ListView1.SetFocus;
end;
procedure TProcListForm.Button2Click(Sender: TObject);
begin
Self.Close;
end;
procedure TProcListForm.FormCreate(Sender: TObject);
begin
Self.Font := Application.MainForm.Font;
end;
procedure TProcListForm.ListView1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if Key = 46 then
Kill1Click(nil);
end;
end.