Hello, I need your help; I can’t solve this problem myself.
procedure TForm2.ListProcesses(TreeView: TTreeView);
var
Proc: TPROCESSENTRY32;
hSnap: HWND;
Looper: BOOL;
vNode: TTreeNode;
Ico: TIcon;
begin
TreeView.Items.Clear;
Proc.dwSize := SizeOf(Proc);
hSnap := CreateToolhelp32Snapshot(TH32CS_SNAPALL, 0);
Ico := TIcon.Create;
try
Looper := Process32First(hSnap, Proc);
while integer(Looper) <> 0 do
begin
vNode := TreeView1.Items.AddChild(nil, Proc.szExeFile + '-PID:.' +ntToStr(Proc.th32ProcessID));
Ico.Handle := ExtractIcon(HINSTANCE, Proc.szExeFile, 0);
if Ico.Handle <> 0 then
begin
ImageList1.AddIcon(Ico);
vNode.ImageIndex := ImageList1.Count - 1;
vNode.SelectedIndex := ImageList1.Count - 1;
end;
Looper := Process32Next(hSnap, proc);
end;
finally
CloseHandle(hSnap);
end;
end;
This way only displays a few icons ((
If there is a way to get all the icons, how does the device manager do it?
Ico.Handle := ExtractIcon(HINSTANCE, Proc.szExeFile, 0);