#include <Windows.h>
DWORD Caculation_CPU(LPVOID lpVoid)
{
MEMORYSTATUS MemoryInfo;
DWORD PercentIdle = ;
while()
{
DWORD dwStartTick = GetTickCount();
DWORD dwIdleSt = GetIdleTime();
Sleep();
DWORD dwStopTick = GetTickCount();
DWORD dwIdleEd = GetIdleTime();
PercentIdle = - ((*(dwIdleEd - dwIdleSt)) / (dwStopTick - dwStartTick));
GlobalMemoryStatus(&MemoryInfo); RETAILMSG(,(_T("dwTotalPhys = %d, dwAvailPhys = %d,dwAvailVirtual = %d, System CPU: Usage is %d%%\r\n!!"),MemoryInfo.dwTotalPhys, MemoryInfo.dwAvailPhys, MemoryInfo.dwAvailVirtual, PercentIdle));
}
return ;
} //创建一个线程来计算CPU和内存占用率
DWORD dwThreadID = 0;
CreateThread(NULL,,Caculation_CPU,,NULL,&dwThreadID);