如题!

解决方案 »

  1.   

    好像有个非文档的函数叫什么记不清楚了,zwQuerySystemInfo? zwQuerySystemParam?你从GOOGLE里面搜一下。
      

  2.   

    从网上找的:
    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;
    }