下载本文所附源代码 程序运行效果截图: ![]() |
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结构,程序还可以增加如显示页面文件的大小、地址空间的大小等。 |
一个用vc编的查看内存使用情况的程序源码
最新推荐文章于 2021-02-10 05:06:37 发布