文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>VC++设计图形显示CPU内存利用率程序

VC++设计图形显示CPU内存利用率程序

时间:2010-11-16  来源:秩名

  1)、本程序分两种情况来获取CPU的利用率,NT下利用ntdll.dll中没有公开的API: NtQuerySystemInformation, 9x下利用注册表来获取CPU的利用率

  code:NT

  typedef LONG (WINAPI *PROCNTQSI)(UINT,PVOID,ULONG,PULONG);

  PROCNTQSI NtQuerySystemInformation;

  NtQuerySystemInformation = (PROCNTQSI)GetProcAddress(

  GetModuleHandle("ntdll"),

  "NtQuerySystemInformation"

  );

  if (!NtQuerySystemInformation)

  {

  return;

  }

  // get number of processors in the system

  status = NtQuerySystemInformation(SystemBasicInformation,

  &SysBaseInfo,sizeof(SysBaseInfo),NULL);

  if (status != NO_ERROR)

  {

  return;

  }

  status = NtQuerySystemInformation(SystemTimeInformation,

  &SysTimeInfo,sizeof(SysTimeInfo),0);

  if (status!=NO_ERROR)

  {

  return;

  }

  // get new CPU''s idle time

  status = NtQuerySystemInformation(SystemPerformanceInformation,

  &SysPerfInfo,sizeof(SysPerfInfo),NULL);

  if (status != NO_ERROR)

  {

  return;

  }

  // 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;

  }

标签分类: VC

相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载