sxq9535 2017-04-09 02:58 采纳率: 0%
浏览 1069
已结题

求大神,急!!!帮我用C++用gloabmemorystatusex查看内存总量和当前使用量

#include
#include
#include
#include

#include

using namespace std;
typedef struct MEMORYSTATUSEX {
DWORD dwLength;
DWORD dwMemoryLoad;
DWORDLONG ullTotalPhys;
DWORDLONG ullAvailPhys;
DWORDLONG ullTotalPageFile;
DWORDLONG ullAvailPageFile;
DWORDLONG ullTotalVirtual;
DWORDLONG ullAvailVirtual;
DWORDLONG ullAvailExtendedVirtual;
} MEMORYSTATUSEX, *LPMEMORYSTATUSEX;
void GetMemoryInfo()
{
MEMORYSTATUSEX statex;
statex.dwLength = sizeof (statex);
GlobalMemoryStatusEx(&statex);
CString strInfo = "内存:\r\n";
CString strTemp = "";
// 内存使用率
strTemp.Format("There is %ld percent of memory in use.\r\n", statex.dwMemoryLoad);
strInfo += strTemp;
// 物理内存
strTemp.Format("There are %I64d total Kbytes of physical memory.\r\n", statex.ullTotalPhys/1024);
strInfo += strTemp;
// 可用物理内存
strTemp.Format("There are %I64d free Kbytes of physical memory.\r\n", statex.ullAvailPhys/1024);
strInfo += strTemp;
// 认可用量:总数
strTemp.Format("There are %I64d total Kbytes of paging file.\r\n", statex.ullTotalPageFile/1024);
strInfo += strTemp;
// 认可用量:未用
strTemp.Format("There are %I64d free Kbytes of paging file.\r\n", statex.ullAvailPageFile/1024);
strInfo += strTemp;
// 虚拟内存
strTemp.Format("There are %I64d total Kbytes of virtual memory.\r\n", statex.ullTotalVirtual/1024);
strInfo += strTemp;
// 可用虚拟内存
strTemp.Format("There are %I64d free Kbytes of virtual memory.\r\n", statex.ullAvailVirtual/1024);
strInfo += strTemp;
// ullAvailExtendedVirtual保留字段
strTemp.Format("There are %I64d free Kbytes of extended memory.\r\n", statex.ullAvailExtendedVirtual/1024);
strInfo += strTemp;
m_staticMemory.SetWindowText(strInfo);
}

这是我在网上找的,自己不会改,谁能帮帮我!!拜托了

  • 写回答

1条回答 默认 最新

  • GKatHere 2017-04-09 04:00
    关注

    要改什么,这程序基本不用改。
    如果 MEMORYSTATUSEX 得定义,则注释掉
    如果 GetMemoryInfo要返回值则
    CString GetMemoryInfo()
    {
    //...
    //m_staticMemory.SetWindowText(strInfo);
    return strInfo;
    }
    另外最好定符串前加_T
    _T("内存:\r\n");

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog