z27
asked on
Listview and their associated Icons .
Hello Experts.
Please help me with this code:(tip on Swissdelphicenter )
{Enumerate processes and terminate them }
interface
uses
{...,}TLHelp32 {important !}
// Global Variables, Globale Variablen
var
aSnapshotHandle: THandle;
aProcessEntry32: TProcessEntry32;
implementation
procedure TForm1.BtnRefreshClick(Sen der: TObject);
var
i: Integer;
bContinue: BOOL;
NewItem: TListItem;
begin
ListView1.Items.Clear;
aSnapshotHandle := CreateToolhelp32Snapshot(T H32CS_SNAP PROCESS, 0);
aProcessEntry32.dwSize := SizeOf(aProcessEntry32);
bContinue := Process32First(aSnapshotHa ndle, aProcessEntry32);
while Integer(bContinue) <> 0 do
begin
NewItem := ListView1.Items.Add;
NewItem.Caption := ExtractFileName(aProcessEn try32.szEx eFile);
NewItem.subItems.Add(IntTo Hex(aProce ssEntry32. th32Proces sID, 4));
NewItem.subItems.Add(aProc essEntry32 .szExeFile );
bContinue := Process32Next(aSnapshotHan dle, aProcessEntry32);
end;
CloseHandle(aSnapshotHandl e);
end;
procedure TForm1.ListView1DblClick(S ender: TObject);
var
Ret: BOOL;
PrID: Integer; // processidentifier
Ph: THandle; // processhandle
begin
with ListView1 do
begin
if MessageDlg('Do you want to Terminate "' + ItemFocused.Caption + '"?' + ^J +
'It''s possible the system becames instable or out of' + ^J +
'control......',
mtConfirmation, [mbYes, mbNo], 0) = mrYes then
begin
PrID := StrToInt('$' + ItemFocused.SubItems[0]);
Ph := OpenProcess(1, BOOL(0), PrID);
Ret := TerminateProcess(Ph, 0);
if Integer(Ret) = 0 then
MessageDlg('Cannot terminate "' + ItemFocused.Caption + '"',
mtInformation, [mbOK], 0)
else
ItemFocused.Delete;
end;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
{
ListView1.Columns.Add;
ListView1.Columns.Add;
ListView1.Columns.Add;
ListView1.ViewStyle := vsReport;
}
BtnRefresh.Click;
end;
my question: How extract associated Icons of processes then show in Listview1.
Thank you.
Please help me with this code:(tip on Swissdelphicenter )
{Enumerate processes and terminate them }
interface
uses
{...,}TLHelp32 {important !}
// Global Variables, Globale Variablen
var
aSnapshotHandle: THandle;
aProcessEntry32: TProcessEntry32;
implementation
procedure TForm1.BtnRefreshClick(Sen
var
i: Integer;
bContinue: BOOL;
NewItem: TListItem;
begin
ListView1.Items.Clear;
aSnapshotHandle := CreateToolhelp32Snapshot(T
aProcessEntry32.dwSize := SizeOf(aProcessEntry32);
bContinue := Process32First(aSnapshotHa
while Integer(bContinue) <> 0 do
begin
NewItem := ListView1.Items.Add;
NewItem.Caption := ExtractFileName(aProcessEn
NewItem.subItems.Add(IntTo
NewItem.subItems.Add(aProc
bContinue := Process32Next(aSnapshotHan
end;
CloseHandle(aSnapshotHandl
end;
procedure TForm1.ListView1DblClick(S
var
Ret: BOOL;
PrID: Integer; // processidentifier
Ph: THandle; // processhandle
begin
with ListView1 do
begin
if MessageDlg('Do you want to Terminate "' + ItemFocused.Caption + '"?' + ^J +
'It''s possible the system becames instable or out of' + ^J +
'control......',
mtConfirmation, [mbYes, mbNo], 0) = mrYes then
begin
PrID := StrToInt('$' + ItemFocused.SubItems[0]);
Ph := OpenProcess(1, BOOL(0), PrID);
Ret := TerminateProcess(Ph, 0);
if Integer(Ret) = 0 then
MessageDlg('Cannot terminate "' + ItemFocused.Caption + '"',
mtInformation, [mbOK], 0)
else
ItemFocused.Delete;
end;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
{
ListView1.Columns.Add;
ListView1.Columns.Add;
ListView1.Columns.Add;
ListView1.ViewStyle := vsReport;
}
BtnRefresh.Click;
end;
my question: How extract associated Icons of processes then show in Listview1.
Thank you.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you very much.