您的位置:首页 > 其它

一个用vc编的查看内存使用情况的程序源码

2011-09-29 13:58 447 查看
下载本文所附源代码

程序运行效果截图:


void CMemStateDlg::OnButton1()
{
// TODO: Add your control notification handler code here
MEMORYSTATUS memStatus;
char buf[80];

memStatus.dwLength=sizeof(MEMORYSTATUS);

GlobalMemoryStatus(&memStatus);

DWORD tom=memStatus.dwTotalPhys;
DWORD mem=memStatus.dwAvailPhys;
DWORD res=memStatus.dwAvailVirtual;
tom /= (1024);
mem /= (1024);
res /= (1024);

int m_Total = (int)tom/1024;
int m_Used  = (int)(tom-mem)/1024;
m_CtrProgress.SetRange(0, m_Total);
m_CtrProgress.SetStep(1);
m_CtrProgress.SetPos(m_Used);

sprintf(buf,"%ld",tom);
GetDlgItem(IDC_TOTALMEM)->SetWindowText(buf);
sprintf(buf,"%ld",mem);
GetDlgItem(IDC_AVAILMEM)->SetWindowText(buf);
sprintf(buf,"%ld",res);
GetDlgItem(IDC_VIRTUALMEM)->SetWindowText(buf);
*(buf)='\0';
}


程序运行效果如图所示。

本程序是一个查看内存使用情况的例子,程序不难,都能看懂。程序中用到MEMORYSTATUS结构,程序还可以增加如显示页面文件的大小、地址空间的大小等。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: