2009年5月29日

Delphi 使用 TLHelp32 列出 目前執行緒

在 Form 上放入 TMemo

uses
TLHelp32;

procedure TForm1.FormCreate(Sender: TObject);
var
hProcessSnap: THandle;
ProcessEntry32: TProcessEntry32;

procedure ShowProcess32;
begin
with Memo1.Lines do begin
Add(Format(
'%s ProcessID: %d ParentProcessID: %d Threads: %d Priority: %d',
[
ProcessEntry32.szExeFile,
ProcessEntry32.th32ProcessID,
ProcessEntry32.th32ParentProcessID,
ProcessEntry32.cntThreads,
ProcessEntry32.pcPriClassBase
]));

end;
end;
begin
hProcessSnap := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (hProcessSnap = INVALID_HANDLE_VALUE) then Exit;
try
ProcessEntry32.dwSize := SizeOf(ProcessEntry32);
if Process32First(hProcessSnap, ProcessEntry32) then begin
ShowProcess32;
repeat
ShowProcess32;
until not Process32Next(hProcessSnap, ProcessEntry32);
end;
finally
CloseHandle(hProcessSnap);
end;
end;

沒有留言:

網誌存檔