C++获取各种系统相关信息

BOOL CSystemInfoDialog::OnInitDialog()  

  //对话框的初始化函数

  { CString DisplayString;

   SYSTEM_INFO SystemInfo;  

  //检测CPU的类型

   ::GetSystemInfo(&&SystemInfo);  

  //WinAPI函数,用以取得系统信息

  if (SystemInfo.wProcessorArchitecture = =  

  PROCESSOR_ARCHITECTURE_INTEL)

  { switch (SystemInfo.wProcessorLevel) {  

  //本程序只演示取得Intel系列CPU的方法

  ……

  //省略对386及486机器的检测

  case 5:

  DisplayString= "Pentium";

  break;

  case 6:

  DisplayString ="Pentium (II/Pro)";

  break; }

   }  

   m_CpuType.SetWindowText(DisplayString);

  //变量m_CpuType是一个CStatic框

  //检测内存状态

   MEMORYSTATUS MemoryStatus;  

  //内存的现行状态结构

   MemoryStatus.dwLength=sizeof(MEMORYSTATUS);  

  //填充结构的大小

   ::GlobalMemoryStatus(&&MemoryStatus);

  //取得内存的状态

   char buffer[20];  

   wsprintf(buffer,"%d bytes",MemoryStatus.dwTotalPhys);

  //dwTotalPhys指示物理内存字节

   m_Memory.SetWindowText(buffer);  

  //变量m_Memory是一个CStatic框

  //检测操作系统版本

   OSverSIONINFO versionInfo;

   //操作系统版本信息结构

   versionInfo.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);

   ::GetVersionEx (&&versionInfo);  

  //取得当前操作系统信息

   if (versionInfo.dwPlatformId = =

   VER_PLATFORM_WIN32_NT)

   {

  //如果操作系统是Windows NT

  ……

  //本文略过对NT系统的检测操作

   }

   else if (versionInfo.dwPlatformId = =

  VER_PLATFORM_WIN32_WINDOWS)  

   {  

  //如果操作系统是Windows 9X系统

  DisplayString="Windows 95";

   if ((versionInfo.dwMajorVersion >= 4)&&&& (versionInfo.dwMinorVersion > 0))  

   {  

  //版本4.1以上系统为Windows98系列

  DisplayString="Windows 98";

  char VersionBuffer[20];  

  //取得操作系统的版本号

  wsprintf(VersionBuffer,"%d.%d",versionInfo.dwMajorVersion,versionInfo.dwMinorVersion);

  m_Version.SetWindowText(VersionBuffer);  

  //在对话框上显示版本信息

   }

   }

   m_System.SetWindowText(DisplayString);  

  //在对话框上显示操作系统类

  //检测鼠标

   int MouseInstall=::GetSystemMetrics(SM_MOUSEPRESENT);  

   if(MouseInstall!=0)  

   m_Mouse.SetWindowText("有");

   int cx,cy;  

  //取得当前显示分辨率

   cx=::GetSystemMetrics(SM_CXSCREEN);  

  //水平分辨率

   cy=::GetSystemMetrics(SM_CYSCREEN);  

  //垂直分辨率

   char Display[20];

   wsprintf(Display,"%d  %d",cx,cy);

  m_Display.SetWindowText(Display);  

  //在对话框上显示分辨率信息

  //取得当前系统的颜色设置

  CDC DC=this->GetDC();  

  int nColors=DC->GetDeviceCaps(NUMCOLORS);  

  if(nColors!=-1)  

  wsprintf(Display,"%d 色",nColors);

  else wsprintf(Display,"高彩或真彩");

  m_ColorDeep.SetWindowText(Display);  

  //取得系统时间

  SYSTEMTIME SystemTime;

  ::GetSystemTime(&&SystemTime);

  wsprintf(Display,"%d-%d-%d",SystemTime.wMonth,SystemTime.wDay,SystemTime.wYear);

  m_SystemDate.SetWindowText(Display);

  //取得Windows系统的路径

  ::GetWindowsDirectory(Display,20);

  m_SystemPath.SetWindowText(Display);

  return TRUE;

  }

你可能感兴趣的:(C++获取各种系统相关信息)