显示 当前CPU 和 内存 占用率 我想做个 点击BUTTON1后 LABEL1 显示当前 CPU LABEL2 显示内存 是实时的数据 希望提供 本人比较菜 最好能做好把程序发到我邮箱 我立刻结贴 谢谢[email protected] 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 代码都贴给你了:function GetCPUUsage(var liOldIdleTime, liOldSystemTime: LARGE_INTEGER): string;{ 返回CPU的利用率}type TSystem_Basic_Information = packed record dwUnknown1: DWORD; uKeMaximumIncrement: ULONG; uPageSize: ULONG; uMmNumberOfPhysicalPages: ULONG; uMmLowestPhysicalPage: ULONG; uMmHighestPhysicalPage: ULONG; uAllocationGranularity: ULONG; pLowestUserAddress: Pointer; pMmHighestUserAddress: Pointer; uKeActiveProcessors: ULONG; bKeNumberProcessors: byte; bUnknown2: byte; wUnknown3: word; end; TSystem_Performance_Information = packed record liIdleTime: LARGE_INTEGER; {LARGE_INTEGER} dwSpare: array[0..75] of DWORD; end; TSystem_Time_Information = packed record liKeBootTime: LARGE_INTEGER; liKeSystemTime: LARGE_INTEGER; liExpTimeZoneBias: LARGE_INTEGER; uCurrentTimeZoneId: ULONG; dwReserved: DWORD; end; TNtQuerySystemInformation = function(infoClass: DWORD; buffer: Pointer; bufSize: DWORD; var returnSize: Dword): DWORD; stdcall;var NtQuerySystemInformation: TNtQuerySystemInformation; SysBaseInfo: TSystem_Basic_Information; SysPerfInfo: TSystem_Performance_Information; SysTimeInfo: TSystem_Time_Information; status: DWORD; {long} dbSystemTime: Double; dbIdleTime: Double;begin Result := '<N/A>'; NtQuerySystemInformation := GetProcAddress(GetModuleHandle('ntdll.dll'), 'NtQuerySystemInformation'); if @NtQuerySystemInformation = nil then Exit; if (NtQuerySystemInformation(0, @SysBaseInfo, SizeOf(SysBaseInfo), status) <> 0) or (NtQuerySystemInformation(3, @SysTimeInfo, SizeOf(SysTimeInfo), status) <> 0) or (NtQuerySystemInformation(2, @SysPerfInfo, SizeOf(SysPerfInfo), status) <> 0) then Exit; if liOldIdleTime.QuadPart <> 0 then begin // CurrentValue = NewValue - OldValue dbIdleTime := Li2Double(SysPerfInfo.liIdleTime) - Li2Double(liOldIdleTime); dbSystemTime := Li2Double(SysTimeInfo.liKeSystemTime) - Li2Double(liOldSystemTime); // CurrentCpuIdle = IdleTime / SystemTime dbIdleTime := dbIdleTime / dbSystemTime; // CurrentCpuUsage% = 100 - (CurrentCpuIdle * 100) / NumberOfProcessors dbIdleTime := 100.0 - dbIdleTime * 100.0 / SysBaseInfo.bKeNumberProcessors{ + 0.5}; // Show Percentage Result := FormatFloat('0.00 %',dbIdleTime); end; liOldIdleTime := SysPerfInfo.liIdleTime; liOldSystemTime := SysTimeInfo.liKeSystemTime;end;function GetSystemMemoryStatus: TMemoryStatus;{ 返回系统内存状态}begin FillChar(Result, SizeOf(Result), 0); Result.dwLength := SizeOf(Result); GlobalMemoryStatus(Result);end; TeeChart怎么导出txt或jpg? 动态连接库的简单问题 如何将mdiaplay.display指定到动态创建的窗体上? 急,,急,,工资管理系统!!1 请教: hongqi162(失踪的月亮) Delphi如何利用Setup API实现驱动程序自动安装 有没有不用连接数据库就能直接在代码中插入多条记录的TDATASET 现在delphi大家用什么版本? 三喜临门,散分3000庆祝(之八) 1000分谁能拿? 一定条件下求字段的最大值 弱弱的问一句:delphi做的软件可以在64位系统中运行吗?
{
返回CPU的利用率
}
type
TSystem_Basic_Information = packed record
dwUnknown1: DWORD;
uKeMaximumIncrement: ULONG;
uPageSize: ULONG;
uMmNumberOfPhysicalPages: ULONG;
uMmLowestPhysicalPage: ULONG;
uMmHighestPhysicalPage: ULONG;
uAllocationGranularity: ULONG;
pLowestUserAddress: Pointer;
pMmHighestUserAddress: Pointer;
uKeActiveProcessors: ULONG;
bKeNumberProcessors: byte;
bUnknown2: byte;
wUnknown3: word;
end; TSystem_Performance_Information = packed record
liIdleTime: LARGE_INTEGER; {LARGE_INTEGER}
dwSpare: array[0..75] of DWORD;
end; TSystem_Time_Information = packed record
liKeBootTime: LARGE_INTEGER;
liKeSystemTime: LARGE_INTEGER;
liExpTimeZoneBias: LARGE_INTEGER;
uCurrentTimeZoneId: ULONG;
dwReserved: DWORD;
end; TNtQuerySystemInformation = function(infoClass: DWORD; buffer: Pointer; bufSize: DWORD; var returnSize: Dword): DWORD; stdcall;
var
NtQuerySystemInformation: TNtQuerySystemInformation;
SysBaseInfo: TSystem_Basic_Information;
SysPerfInfo: TSystem_Performance_Information;
SysTimeInfo: TSystem_Time_Information;
status: DWORD; {long}
dbSystemTime: Double;
dbIdleTime: Double;
begin
Result := '<N/A>'; NtQuerySystemInformation := GetProcAddress(GetModuleHandle('ntdll.dll'), 'NtQuerySystemInformation');
if @NtQuerySystemInformation = nil then Exit;
if (NtQuerySystemInformation(0, @SysBaseInfo, SizeOf(SysBaseInfo), status) <> 0)
or (NtQuerySystemInformation(3, @SysTimeInfo, SizeOf(SysTimeInfo), status) <> 0)
or (NtQuerySystemInformation(2, @SysPerfInfo, SizeOf(SysPerfInfo), status) <> 0) then Exit; if liOldIdleTime.QuadPart <> 0 then
begin
// CurrentValue = NewValue - OldValue
dbIdleTime := Li2Double(SysPerfInfo.liIdleTime) - Li2Double(liOldIdleTime);
dbSystemTime := Li2Double(SysTimeInfo.liKeSystemTime) - Li2Double(liOldSystemTime); // CurrentCpuIdle = IdleTime / SystemTime
dbIdleTime := dbIdleTime / dbSystemTime; // CurrentCpuUsage% = 100 - (CurrentCpuIdle * 100) / NumberOfProcessors
dbIdleTime := 100.0 - dbIdleTime * 100.0 / SysBaseInfo.bKeNumberProcessors{ + 0.5}; // Show Percentage
Result := FormatFloat('0.00 %',dbIdleTime);
end;
liOldIdleTime := SysPerfInfo.liIdleTime;
liOldSystemTime := SysTimeInfo.liKeSystemTime;
end;function GetSystemMemoryStatus: TMemoryStatus;
{
返回系统内存状态
}
begin
FillChar(Result, SizeOf(Result), 0);
Result.dwLength := SizeOf(Result);
GlobalMemoryStatus(Result);
end;