现在的位置: 首页 > 自动控制 > 工业·编程 > 正文

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

2013-02-06 22:52 工业·编程 ⁄ 共 2258字 ⁄ 字号 暂无评论

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)

给我留言

留言无头像?