GlobalMemoryStatusEx函數用於擷取系統記憶體資訊:
BOOL WINAPI GlobalMemoryStatusEx(
__inout LPMEMORYSTATUSEX lpBuffer
);
範例程式碼:
void CTestDlg::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);
}
運行結果: