请问,各位哥们,Api函数CreateToolhelp32Snapshot() Process32First() Process32Ne

  • 主题发起人 主题发起人 旭日升
  • 开始时间 开始时间

旭日升

Unregistered / Unconfirmed
GUEST, unregistred user!
请问,各位哥们,Api函数CreateToolhelp32Snapshot() &nbsp;Process32First() &nbsp;Process32Next() 怎么用(100分)<br />请问,各位哥们,Api函数CreateToolhelp32Snapshot()<br>&nbsp;Process32First() &nbsp;Process32Next() 怎么用<br><br>以下代码错在那里的?<br>procedure TForm1.Button5Click(Sender: TObject);<br>Type<br>&nbsp; S_Process=Record<br>&nbsp; &nbsp; dwSize: DWORD;<br>&nbsp; &nbsp; cntUsage: DWORD;<br>&nbsp; &nbsp; th32ProcessID: DWORD;<br>&nbsp; &nbsp; th32DefaultHeapID: DWORD;<br>&nbsp; &nbsp; th32ModuleID: DWORD;<br>&nbsp; &nbsp; cntThreads: DWORD;<br>&nbsp; &nbsp; th32ParentProcessID: DWORD;<br>&nbsp; &nbsp; pcPriClassBase: LONGINT;<br>&nbsp; &nbsp; dwFlags: DWORD;<br>&nbsp; &nbsp; szExeFile :PChar;<br>&nbsp; End ;<br>Var<br>&nbsp; &nbsp;msgProcess: S_Process;<br>&nbsp; &nbsp;Snapshot : DWord ;<br>begin<br>&nbsp; &nbsp; &nbsp; Snapshot := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, GetCurrentProcessId() &nbsp;) ;<br>&nbsp; &nbsp; &nbsp; msgProcess.dwSize := 296 ;<br>&nbsp; &nbsp; &nbsp; Process32First(Snapshot, msgProcess) ;<br>&nbsp; &nbsp; &nbsp;// ...........<br>end;<br>
 
procedure TForm1.Button1Click(Sender: TObject);<br>Var<br>&nbsp; msgProcess: tagPROCESSENTRY32;<br>&nbsp; Snapshot : DWord ;<br>begin<br>&nbsp; Snapshot := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, GetCurrentProcessId()) ;<br>&nbsp; msgProcess.dwSize := 296 ;<br>&nbsp; Process32First(Snapshot, msgProcess) ;<br>end;
 
unit Unit1;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Classes, Graphics,<br>&nbsp; TLHelp32, Controls, Forms, Dialogs, StdCtrls;<br><br>type<br>&nbsp; TProcessInfo = record<br>&nbsp; &nbsp; ExeFile: string;<br>&nbsp; &nbsp; ProcessID: DWORD;<br>&nbsp; end;<br>&nbsp; pProcessInfo = ^TProcessInfo;<br><br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; Memo1: TMemo;<br>&nbsp; &nbsp; procedure FormCreate(Sender: TObject);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>var<br>&nbsp; Form1 &nbsp; &nbsp; &nbsp; &nbsp;: TForm1;<br><br>implementation<br><br>{$R *.DFM}<br><br>procedure TForm1.FormCreate(Sender: TObject);<br>var<br>&nbsp; p &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;: pProcessInfo;<br>&nbsp; ContinueLoop : BOOL;<br>var<br>&nbsp; FSnapshotHandle: THandle;<br>&nbsp; FProcessEntry32: TProcessEntry32;<br>begin<br>&nbsp; FSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);<br>&nbsp; FProcessEntry32.dwSize := Sizeof(FProcessEntry32);<br>&nbsp; ContinueLoop := Process32First(FSnapshotHandle, FProcessEntry32);<br>&nbsp; while integer(ContinueLoop) &lt;&gt; 0 do<br>&nbsp; begin<br>&nbsp; &nbsp; New(p);<br>&nbsp; &nbsp; p.ExeFile := FProcessEntry32.szExeFile;<br>&nbsp; &nbsp; p.ProcessID := FProcessEntry32.th32ProcessID;<br>&nbsp; &nbsp; Memo1.lines.Add(Format('进程ID号:%d &nbsp; 文件名:%s', [p.ProcessID, p.ExeFile]));<br>&nbsp; &nbsp; ContinueLoop := Process32Next(FSnapshotHandle, FProcessEntry32);<br>&nbsp; end;<br>end;<br><br>end.<br>
 
怎么结贴?我要给你们加分了
 
后退
顶部