C++ 怎么实现获取当前PC 硬盘 内存的大小以及已使用大小,加上CPU使用率

[复制链接]
查看11 | 回复2 | 2009-8-13 11:10:12 | 显示全部楼层 |阅读模式
获取硬盘空间,使用:GetDiskFreeSpace或GetDiskFreeSpaceEx获取内存状态,使用:GlobalMemoryStatus或GlobalMemoryStatusEx获取CPU使用率,使用:NtQuerySystemInformation查询关于处理器性能(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION)
回复

使用道具 举报

千问 | 2009-8-13 11:10:12 | 显示全部楼层
可以通过编程实现,源代码如下://Sample output://There is
51 percent of memory in use.//There are 2029968 total KB of physical memory.//There are987388 freeKB of physical memory.//There are 3884620 total KB of paging file.//There are 2799776 freeKB of paging file.//There are 2097024 total KB of virtual memory.//There are 2084876 freeKB of virtual memory.//There are
0 freeKB of extended memory.#include #include #include // Use to convert bytes to KB#define DIV 1024// Specify the width of the field in which to print the numbers. // The asterisk in the format specifier "%*I64d" takes an integer // argument and uses it to pad and right justify the number.#define WIDTH 7void _tmain(){MEMORYSTATUSEX statex;statex.dwLength = sizeof (statex);GlobalMemoryStatusEx (&statex);_tprintf (TEXT("There is%*ld percent of memory in use.\n"),
WIDTH, statex.dwMemoryLoad);_tprintf (TEXT("There are %*I64d total KB of physical memory.\n"),
WIDTH, statex.ullTotalPhys/DIV);_tprintf (TEXT("There are %*I64d freeKB of physical memory.\n"),
WIDTH, statex.ullAvailPhys/DIV);_tprintf (TEXT("There are %*I64d total KB of paging file.\n"),
WIDTH, statex.ullTotalPageFile/DIV);_tprintf (TEXT("There are %*I64d freeKB of paging file.\n"),
WIDTH, statex.ullAvailPageFile/DIV);_tprintf (TEXT("There are %*I64d total KB of virtual memory.\n"),
WIDTH, statex.ullTotalVirtual/DIV);_tprintf (TEXT("There are %*I64d freeKB of virtual memory.\n"),
WIDTH, statex.ullAvailVirtual/DIV);// Show the amount of extended memory available._tprintf (TEXT("There are %*I64d freeKB of extended memory.\n"),
WIDTH, statex.ullAvailExtendedVirtual/DIV);}运行后结果就能获取当前PC的硬盘大小、已使用大小和CPU的使用率。
回复

使用道具 举报

千问 | 2009-8-13 11:10:12 | 显示全部楼层
上csdn里一大把。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行