C++获取系统内存及分别率

来源:互联网 发布:java开发面试题 编辑:程序博客网 时间:2024/05/12 23:04
1.获得系统内存情况MEMORYSTATUS *mymem;char s[6][20];//获得系统内存情况mymem = new MEMORYSTATUS;GlobalMemoryStatus(mymem);    if(mymem->dwMemoryLoad>1024){mymem->dwMemoryLoad/=1024;_itoa(mymem->dwMemoryLoad,s[0],10);m_usedmem=s[0];m_usedmem+=" KB";}    else{        _itoa(mymem->dwMemoryLoad,s[0],10);        m_usedmem=s[0];m_usedmem+=" Byte";}_itoa(mymem->dwTotalPhys/1024,s[1],10);_itoa(mymem->dwTotalPageFile/1024,s[2],10);_itoa(mymem->dwAvailPageFile/1024,s[3],10);    _itoa(mymem->dwTotalVirtual/1024,s[4],10);_itoa(mymem->dwAvailVirtual/1024,s[5],10);m_availvirtual.Format("%s KB",s[5]);m_totalvirtual.Format("%s KB",s[4]);m_totalpage.Format("%s KB",s[2]);m_availpage.Format("%s KB",s[3]);m_totalmem.Format("%s KB",s[1]);UpdateData(FALSE);delete mymem;//获取操作系统信息char windir[MAX_PATH];//获得Windows目录GetWindowsDirectory(windir,MAX_PATH);m_Windir.SetWindowText(windir);//获得Windows系统目录GetSystemDirectory(windir,MAX_PATH);m_Winsys.SetWindowText(windir);//获得操作系统信息OSVERSIONINFO osvi;CString winver,os;osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);GetVersionEx (&osvi);switch(osvi.dwPlatformId){case 0:os = "Windows 3.x";break;case 1:os = "Windows 95/98/Me";break;case 2:os = "Windows NT/2000";break;}winver.Format("Version:%d.%d Builder:%d",osvi.dwMajorVersion,osvi.dwMinorVersion,osvi.dwBuildNumber);m_Winver.SetWindowText(winver);m_Winplt.SetWindowText(os);//获取CPU信息char s[20];LPSYSTEM_INFO mysys;mysys=new SYSTEM_INFO;GetSystemInfo(mysys);//_itoa(mysys->wProcessorArchitecture,s,10);  //  m_cpuid=s;_itoa(mysys->dwNumberOfProcessors,s,10);m_cpunum=s;_itoa(mysys->dwProcessorType,s,10);m_cputype=s;switch (mysys->wProcessorLevel){  case 3:    m_cpulevel="Intel 80386";break;  case 4:        m_cpulevel="Intel 80486";         break;  case 5:m_cpulevel="Pentium";break;  default:m_cpulevel="未知的CPU";}_itoa(mysys->wProcessorRevision,s,10);m_cpurevision=s;delete mysys;UpdateData(FALSE);//获取屏幕分辨率信息CString scrxy;int x = GetSystemMetrics(SM_CXSCREEN);int y = GetSystemMetrics(SM_CYSCREEN);scrxy.Format("%d * %d",x,y);m_Scr.SetWindowText(scrxy)