Link to home
Start Free TrialLog in
Avatar of z27
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(Sender: TObject);  
var  
  i: Integer;  
  bContinue: BOOL;  
  NewItem: TListItem;  
begin  
  ListView1.Items.Clear;  
  aSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);  
  aProcessEntry32.dwSize := SizeOf(aProcessEntry32);  
  bContinue := Process32First(aSnapshotHandle, aProcessEntry32);  
  while Integer(bContinue) <> 0 do  
  begin  
    NewItem := ListView1.Items.Add;  
    NewItem.Caption := ExtractFileName(aProcessEntry32.szExeFile);  
    NewItem.subItems.Add(IntToHex(aProcessEntry32.th32ProcessID, 4));  
    NewItem.subItems.Add(aProcessEntry32.szExeFile);  
    bContinue := Process32Next(aSnapshotHandle, aProcessEntry32);  
  end;  
  CloseHandle(aSnapshotHandle);  
end;  


procedure TForm1.ListView1DblClick(Sender: 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.
ASKER CERTIFIED SOLUTION
Avatar of Ferruccio Accalai
Ferruccio Accalai
Flag of Italy image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of z27
z27

ASKER

OK ,It works well...
  Thank you very much.