想了好久的问题 vc 如何获得当前每个cpu的利用率以及占用内存大小? 如题! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 好像有个非文档的函数叫什么记不清楚了,zwQuerySystemInfo? zwQuerySystemParam?你从GOOGLE里面搜一下。 从网上找的:UINT GetCpuUsgesNt(){ SYSTEM_PERFORMANCE_INFORMATION SysPerfInfo; SYSTEM_TIME_INFORMATION SysTimeInfo; SYSTEM_BASIC_INFORMATION SysBaseInfo; double dbIdleTime; double dbSystemTime; LONG status; typedef LONG (WINAPI *PROCNTQSI)(UINT,PVOID,ULONG,PULONG); PROCNTQSI NtQuerySystemInformation; NtQuerySystemInformation = (PROCNTQSI)GetProcAddress( GetModuleHandle("ntdll"), "NtQuerySystemInformation" ); if (!NtQuerySystemInformation) { return 0; } // get number of processors in the system status = NtQuerySystemInformation(SystemBasicInformation, &SysBaseInfo,sizeof(SysBaseInfo),NULL); if (status != NO_ERROR) { return 0; } status = NtQuerySystemInformation(SystemTimeInformation, &SysTimeInfo,sizeof(SysTimeInfo),0); if (status!=NO_ERROR) { return 0; } // get new CPU's idle time status = NtQuerySystemInformation(SystemPerformanceInformation, &SysPerfInfo,sizeof(SysPerfInfo),NULL); if (status != NO_ERROR) { return 0; } // if it's a first call - skip it if (m_liOldIdleTime.QuadPart != 0) { // CurrentValue = NewValue - OldValue dbIdleTime = Li2Double(SysPerfInfo.liIdleTime) - Li2Double(m_liOldIdleTime); dbSystemTime = Li2Double(SysTimeInfo.liKeSystemTime) - Li2Double(m_liOldSystemTime); // CurrentCpuIdle = IdleTime / SystemTime dbIdleTime = dbIdleTime / dbSystemTime; // CurrentCpuUsage% = 100 - (CurrentCpuIdle * 100) / NumberOfProcessors dbIdleTime = 100.0 - dbIdleTime * 100.0 / (double)SysBaseInfo.bKeNumberProcessors + 0.5; m_fNewUsges = (UINT)dbIdleTime; } // store new CPU's idle and system time m_liOldIdleTime = SysPerfInfo.liIdleTime; m_liOldSystemTime = SysTimeInfo.liKeSystemTime; return m_fNewUsges;}UINT GetMemUsgesNt(){ MEMORYSTATUS MemStat; MemStat.dwLength = sizeof(MEMORYSTATUS); GlobalMemoryStatus(&MemStat); UINT m_ulNewUsges = MemStat.dwMemoryLoad; //DrawMemUsges(); return m_ulNewUsges;} 可以将某个结构体变量插入到数据库中的某个字段里吗? 救急!在线等!access长二进制数据写入读出为什么会不一样啊? 登陆问题! 在同一个线程中postmessage也是马上返回的吗 菜单命令更新有什么用? 大问题,为什么微软也会死掉!--不得灌水 关于CStringArray,高手请进!!!! 关于vector的问题 如何读取注册表的默认值?? 为何win2000不能识别现行版本? memcpy长时间运行会造成内存出错的问题 求助C和C++,VC和VC++在应用范围上有什么不同呢
UINT GetCpuUsgesNt()
{
SYSTEM_PERFORMANCE_INFORMATION SysPerfInfo;
SYSTEM_TIME_INFORMATION SysTimeInfo;
SYSTEM_BASIC_INFORMATION SysBaseInfo;
double dbIdleTime;
double dbSystemTime;
LONG status;
typedef LONG (WINAPI *PROCNTQSI)(UINT,PVOID,ULONG,PULONG);
PROCNTQSI NtQuerySystemInformation; NtQuerySystemInformation = (PROCNTQSI)GetProcAddress(
GetModuleHandle("ntdll"),
"NtQuerySystemInformation"
); if (!NtQuerySystemInformation)
{
return 0;
} // get number of processors in the system
status = NtQuerySystemInformation(SystemBasicInformation,
&SysBaseInfo,sizeof(SysBaseInfo),NULL); if (status != NO_ERROR)
{
return 0;
} status = NtQuerySystemInformation(SystemTimeInformation,
&SysTimeInfo,sizeof(SysTimeInfo),0);
if (status!=NO_ERROR)
{
return 0;
} // get new CPU's idle time
status = NtQuerySystemInformation(SystemPerformanceInformation,
&SysPerfInfo,sizeof(SysPerfInfo),NULL); if (status != NO_ERROR)
{
return 0;
}
// if it's a first call - skip it
if (m_liOldIdleTime.QuadPart != 0)
{
// CurrentValue = NewValue - OldValue
dbIdleTime = Li2Double(SysPerfInfo.liIdleTime) - Li2Double(m_liOldIdleTime);
dbSystemTime = Li2Double(SysTimeInfo.liKeSystemTime) - Li2Double(m_liOldSystemTime); // CurrentCpuIdle = IdleTime / SystemTime
dbIdleTime = dbIdleTime / dbSystemTime; // CurrentCpuUsage% = 100 - (CurrentCpuIdle * 100) / NumberOfProcessors
dbIdleTime = 100.0 - dbIdleTime * 100.0 / (double)SysBaseInfo.bKeNumberProcessors + 0.5; m_fNewUsges = (UINT)dbIdleTime;
} // store new CPU's idle and system time
m_liOldIdleTime = SysPerfInfo.liIdleTime;
m_liOldSystemTime = SysTimeInfo.liKeSystemTime;
return m_fNewUsges;}UINT GetMemUsgesNt()
{
MEMORYSTATUS MemStat;
MemStat.dwLength = sizeof(MEMORYSTATUS);
GlobalMemoryStatus(&MemStat);
UINT m_ulNewUsges = MemStat.dwMemoryLoad;
//DrawMemUsges();
return m_ulNewUsges;
}