Bonjour a tous,
j'ai un enorme problemeavec une ListBox...
Je voudrais récupérer les applications en cours sur Windows j'ai un tutorial sur ca
mais le probleme c'est que Delphi m'indique une erreure sur une ListBox, voyez mon code :
Merci de votre aide
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 [...]type TForm3 = class(TForm) ListBox1: TListBox; Label1: TLabel; procedure ListBox1Click(Sender: TObject);//l'erreure est ici d'apres delphi procedure FormActivate(Sender: TObject); procedure ListBox1DblClick(Sender: TObject); [...] function UpString(Str: string): string; var i: integer; begin result:=''; for i:=1 to length(str) do result:=result+UpCase(str[i]); end; function GetProcessId(ProgName:string):cardinal; var Snaph:thandle; Proc:tprocessentry32; PId:cardinal; begin PId:=0; Proc.dwSize:=sizeof(Proc); Snaph:=createtoolhelp32snapshot(TH32CS_SNAPALL,0); process32first(Snaph,Proc); if UpString(extractfilename(Proc.szExeFile))=UpString(ProgName) then PId:=Proc.th32ProcessID else begin while process32next(Snaph,Proc) do begin if extractfilename(Proc.szExeFile)=ProgName then PId:=Proc.th32ProcessID; end; end; Closehandle(Snaph); result:=PId; end; function GetProcessList():TStringList; var Snaph:thandle; Proc:tprocessentry32; PList:TStringList; begin PList:= TStringList.Create(); PList.Clear; Proc.dwSize:=sizeof(Proc); Snaph:=createtoolhelp32snapshot(TH32CS_SNAPALL,0); process32first(Snaph,Proc); PList.Add(extractfilename(proc.szExeFile)); while process32next(Snaph,Proc) do PList.Add(extractfilename(Proc.szExeFile)); result:=PList; Closehandle(Snaph); end; procedure TForm3.FormActivate(Sender: TObject); var TSL : TStringList; begin Listbox1.Clear; TSL := GetProcessList; Try Listbox1.Items.Assign(TSL); Finally TSL.Free; end; end ; procedure TForm3.ListBox1DblClick(Sender: TObject); var Proch:thandle; PId:cardinal; begin PId:=GetProcessId(Listbox1.items[Listbox1.itemindex]); Proch:=openprocess(PROCESS_ALL_ACCESS ,true,PId); if not terminateprocess(Proch,PId) then showmessage('Impossible d''arrete '+Listbox1.items[Listbox1.itemindex]) else begin Listbox1.Clear; Listbox1.Items:=GetProcessList(); end; Closehandle(Proch); end;
Partager