unit Unit1;interfaceuses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, ComCtrls, CommCtrl, StdCtrls, Menus,WinSpool, ExtCtrls, Validat, Buttons, Registry;type TForm1 = class(TForm) Button1: TButton; Label1: TLabel; Label2: TLabel; Timer1: TTimer; Button2: TButton; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure Timer1Timer(Sender: TObject); private { Private-Deklarationen } started : boolean; reg : TRegistry; public { Public-Deklarationen } end;var Form1: TForm1;implementation{$R *.DFM}procedure TForm1.Button1Click(Sender: TObject); var Dummy : array[0..1024] of byte;begin Reg:=TRegistry.Create; Reg.RootKey:=HKEY_DYN_DATA; //统计数据在这个表项下 Reg.OpenKey('PerfStats\StartStat',false); // Reg.ReadBinaryData('KERNEL\CPUUsage',Dummy,Sizeof(Dummy)); Reg.CloseKey; started:=true; end;procedure TForm1.Timer1Timer(Sender: TObject); var CPUU : integer;begin if started then begin Reg.OpenKey('PerfStats\StatData',false); Reg.ReadBinaryData('KERNEL\CPUUsage',CPUU,SizeOf(Integer)); Reg.CloseKey; Label1.Caption:=IntToStr(CPUU)+'%'; end; end;procedure TForm1.Button2Click(Sender: TObject); var Dummy : array[0..1024] of byte;begin 'PerfStats/StopStat' } Reg.OpenKey('PerfStats\StopStat',false); Reg.ReadBinaryData('KERNEL\CPUUsage',Dummy,SizeOf(Dummy)); Reg.Free; Started:=false; end;end.
Structure of TMemoryStatus: TMemoryStatus = record dwLength: DWORD; dwMemoryLoad: DWORD; dwTotalPhys: DWORD; dwAvailPhys: DWORD; dwTotalPageFile: DWORD; dwAvailPageFile: DWORD; dwTotalVirtual: DWORD; dwAvailVirtual: DWORD;Function called to populate TMemoryStatus:procedure GlobalMemoryStatus(var lpBuffer: TMemoryStatus); stdcall;WINAPI help for said function: VOID GlobalMemoryStatus( // pointer to the memory status structure LPMEMORYSTATUS lpBuffer ); Code for populating a TMemo with Information about system resources:unit Unit1;interfaceuses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;type TForm1 = class(TForm) Button1: TButton; Memo1: TMemo; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1;implementation{$R *.DFM}procedure TForm1.Button1Click(Sender: TObject); var MemoryStatus: TMemoryStatus;begin Memo1.Lines.Clear; MemoryStatus.dwLength := SizeOf(MemoryStatus); GlobalMemoryStatus(MemoryStatus); with MemoryStatus do begin // Size of MemoryStatus record Memo1.Lines.Add(IntToStr(dwLength) + ' Size of ''MemoryStatus'' record'); // Per-Cent of Memory in use by your system Memo1.Lines.Add(IntToStr(dwMemoryLoad) + '% memory in use'); // The amount of Total Physical memory allocated to your system. Memo1.Lines.Add(IntToStr(dwTotalPhys) + ' Total Physical Memory in bytes'); // The amount available of physical memory in your system. Memo1.Lines.Add(IntToStr(dwAvailPhys) + ' Available Physical Memory in bytes'); // The amount of Total Bytes allocated to your page file. Memo1.Lines.Add(IntToStr(dwTotalPageFile) + ' Total Bytes of Paging File'); // The amount of available bytes in your page file. Memo1.Lines.Add(IntToStr(dwAvailPageFile) + ' Available bytes in paging file'); // The amount of Total bytes allocated to this program // (generally 2 gigabytes of virtual space). Memo1.Lines.Add(IntToStr(dwTotalVirtual) + ' User Bytes of Address space'); // The amount of avalable bytes that is left to your program to use. Memo1.Lines.Add(IntToStr(dwAvailVirtual) + ' Available User bytes of address space'); end; // with end; // procedureend.
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ComCtrls, CommCtrl, StdCtrls, Menus,WinSpool, ExtCtrls, Validat, Buttons,
Registry;type
TForm1 = class(TForm)
Button1: TButton;
Label1: TLabel;
Label2: TLabel;
Timer1: TTimer;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private-Deklarationen }
started : boolean;
reg : TRegistry;
public
{ Public-Deklarationen }
end;var
Form1: TForm1;implementation{$R *.DFM}procedure TForm1.Button1Click(Sender: TObject);
var
Dummy : array[0..1024] of byte;begin
Reg:=TRegistry.Create;
Reg.RootKey:=HKEY_DYN_DATA; //统计数据在这个表项下
Reg.OpenKey('PerfStats\StartStat',false); // Reg.ReadBinaryData('KERNEL\CPUUsage',Dummy,Sizeof(Dummy));
Reg.CloseKey;
started:=true;
end;procedure TForm1.Timer1Timer(Sender: TObject);
var
CPUU : integer;begin
if started then
begin
Reg.OpenKey('PerfStats\StatData',false);
Reg.ReadBinaryData('KERNEL\CPUUsage',CPUU,SizeOf(Integer));
Reg.CloseKey;
Label1.Caption:=IntToStr(CPUU)+'%';
end;
end;procedure TForm1.Button2Click(Sender: TObject);
var
Dummy : array[0..1024] of byte;begin
'PerfStats/StopStat' }
Reg.OpenKey('PerfStats\StopStat',false);
Reg.ReadBinaryData('KERNEL\CPUUsage',Dummy,SizeOf(Dummy));
Reg.Free;
Started:=false;
end;end.
dwLength: DWORD;
dwMemoryLoad: DWORD;
dwTotalPhys: DWORD;
dwAvailPhys: DWORD;
dwTotalPageFile: DWORD;
dwAvailPageFile: DWORD;
dwTotalVirtual: DWORD;
dwAvailVirtual: DWORD;Function called to populate TMemoryStatus:procedure GlobalMemoryStatus(var lpBuffer: TMemoryStatus); stdcall;WINAPI help for said function: VOID GlobalMemoryStatus(
// pointer to the memory status structure
LPMEMORYSTATUS lpBuffer
); Code for populating a TMemo with Information about system resources:unit Unit1;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.DFM}procedure TForm1.Button1Click(Sender: TObject);
var
MemoryStatus: TMemoryStatus;begin Memo1.Lines.Clear; MemoryStatus.dwLength := SizeOf(MemoryStatus); GlobalMemoryStatus(MemoryStatus); with MemoryStatus do
begin
// Size of MemoryStatus record
Memo1.Lines.Add(IntToStr(dwLength) +
' Size of ''MemoryStatus'' record');
// Per-Cent of Memory in use by your system
Memo1.Lines.Add(IntToStr(dwMemoryLoad) +
'% memory in use');
// The amount of Total Physical memory allocated to your system.
Memo1.Lines.Add(IntToStr(dwTotalPhys) +
' Total Physical Memory in bytes');
// The amount available of physical memory in your system.
Memo1.Lines.Add(IntToStr(dwAvailPhys) +
' Available Physical Memory in bytes');
// The amount of Total Bytes allocated to your page file.
Memo1.Lines.Add(IntToStr(dwTotalPageFile) +
' Total Bytes of Paging File');
// The amount of available bytes in your page file.
Memo1.Lines.Add(IntToStr(dwAvailPageFile) +
' Available bytes in paging file');
// The amount of Total bytes allocated to this program
// (generally 2 gigabytes of virtual space).
Memo1.Lines.Add(IntToStr(dwTotalVirtual) +
' User Bytes of Address space');
// The amount of avalable bytes that is left to your program to use.
Memo1.Lines.Add(IntToStr(dwAvailVirtual) +
' Available User bytes of address space');
end; // with
end; // procedureend.
检索表达式: cpu占用率 查看,用时 1062 微秒。共检索到 3481 个记录,显示 1 - 20 下页