35 lines
655 B
C
35 lines
655 B
C
|
|
#pragma once
|
|||
|
|
|
|||
|
|
#include <pdh.h>
|
|||
|
|
#include <pdhmsg.h>
|
|||
|
|
|
|||
|
|
#pragma comment(lib,"PDH.lib")
|
|||
|
|
|
|||
|
|
#define MAX_RAW_VALUES 20
|
|||
|
|
|
|||
|
|
//process <20><>Ŀ<EFBFBD>µ<EFBFBD>% Processor Time<6D><65><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǹ<EFBFBD><C7B9>ڽ<EFBFBD><DABD><EFBFBD>CPUʹ<55>ʵ<EFBFBD>
|
|||
|
|
const char szCounterName[] = "\\Processor(_Total)\\% Processor Time";
|
|||
|
|
|
|||
|
|
typedef struct _tag_PDHCounterStruct {
|
|||
|
|
HCOUNTER hCounter;
|
|||
|
|
int nNextIndex;
|
|||
|
|
int nOldestIndex;
|
|||
|
|
int nRawCount;
|
|||
|
|
PDH_RAW_COUNTER a_RawValue[MAX_RAW_VALUES];
|
|||
|
|
} PDHCOUNTERSTRUCT, *PPDHCOUNTERSTRUCT;
|
|||
|
|
|
|||
|
|
|
|||
|
|
class CCpuUsage
|
|||
|
|
{
|
|||
|
|
public:
|
|||
|
|
CCpuUsage();
|
|||
|
|
virtual ~CCpuUsage();
|
|||
|
|
BOOL Init();
|
|||
|
|
int GetUsage();
|
|||
|
|
|
|||
|
|
protected:
|
|||
|
|
|
|||
|
|
PPDHCOUNTERSTRUCT m_pCounterStruct;
|
|||
|
|
HQUERY m_hQuery;
|
|||
|
|
};
|