⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 systeminfo.cpp

📁 Visual C++编写的工程解析器源代码
💻 CPP
字号:
// SystemInfo.cpp: implementation of the CSystemInfo class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "parsecproj.h"
#include "SystemInfo.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CSystemInfo::CSystemInfo()
{
}

CSystemInfo::~CSystemInfo()
{
}

//得到系统软/硬件信息
LPSYSINFO CSystemInfo::GetSysInfo()
{
	//得到Windows版本信息
	OSVERSIONINFO osVersionInfo;
	osVersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
	::GetVersionEx(&osVersionInfo);
	
	m_lpSysInfo.szWindowsVersion.Format("%ld.%ld.%ld", osVersionInfo.dwMajorVersion,
		osVersionInfo.dwMinorVersion, osVersionInfo.dwBuildNumber);

	/***********************获得操作系统类型******************/
	CString strWinType = "";
	switch(osVersionInfo.dwPlatformId)
	{
	case VER_PLATFORM_WIN32s:
		strWinType = "Microsoft Windows 3.1";
		break;

	case VER_PLATFORM_WIN32_WINDOWS:
		if(osVersionInfo.dwMajorVersion == 4 && osVersionInfo.dwMinorVersion == 0)
			strWinType = "Microsoft Windows 95";

		else if(osVersionInfo.dwMajorVersion == 4 && osVersionInfo.dwMinorVersion == 10)
		{
			strWinType = "Microsoft Windows 98";
			if(osVersionInfo.szCSDVersion[1] == 'A')
				strWinType += "SE";
		}
		else if(osVersionInfo.dwMajorVersion == 4 && osVersionInfo.dwMinorVersion == 90)
			strWinType = "Microsoft Windows Millennium Edition";

		break;
		
	case VER_PLATFORM_WIN32_NT:
		{
			if(osVersionInfo.dwMajorVersion < 4)
				strWinType = "Microsoft Windows NT ";
			else if(osVersionInfo.dwMajorVersion == 5 && osVersionInfo.dwMinorVersion == 0)
				strWinType = "Microsoft Windows 2000 ";
			
			//检查当前操作系统的确切型号
			HKEY hKey;
			char szProductType[80];
			DWORD dwBufLen;
			
			RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Control\\ProductOptions", 
				0, KEY_QUERY_VALUE, &hKey );

			RegQueryValueEx(hKey, "ProductType", NULL, NULL,
				(LPBYTE)szProductType, &dwBufLen);

			RegCloseKey(hKey);

			if ( lstrcmpi( "WINNT", szProductType) == 0 )
				strWinType += "Professional";

			if ( lstrcmpi( "LANMANNT", szProductType) == 0 )
				strWinType += "Server";

			if ( lstrcmpi( "SERVERNT", szProductType) == 0 )
				strWinType += "Advanced Server";	
		}
		break;

	default:
		strWinType = "UnKnown Windows Type";
		
	}
	m_lpSysInfo.szWindowsType = strWinType;

	/***********************获得系统内存信息******************/

	//得到内存状态
	MEMORYSTATUS memoryStatus;

	memset (&memoryStatus, sizeof (MEMORYSTATUS), 0);
	memoryStatus.dwLength = sizeof (MEMORYSTATUS);

	GlobalMemoryStatus (&memoryStatus);
	
	m_lpSysInfo.szPhysicMem = memoryStatus.dwTotalPhys;	
		
	m_lpSysInfo.szNoUsePhysicMem = memoryStatus.dwAvailPhys;

	m_lpSysInfo.szAvailVirtualMem = memoryStatus.dwAvailVirtual;
	m_lpSysInfo.szTotalVirtualMem = memoryStatus.dwTotalVirtual;

	/***********************获得系统磁盘空间信息******************/
	m_lpSysInfo.szDiskCount = 0;

	ULONGLONG ullTotalSpace = 0, ullFreeSpace = 0, ullFreeByte = 0,	ullSumTotal = 0; 
	long int ullSumFree = 0;

	char szDriver[4];
	for(int i = 0; i < 26; ++i)
	{
		szDriver[0] = 'A' + i;
		szDriver[1] = ':';
		szDriver[2] = '\\';
		szDriver[3] = 0;
		UINT uDriverType = ::GetDriveType(szDriver);
		
		if(uDriverType != DRIVE_FIXED)
			continue;
		
		if(!GetDiskFreeSpaceEx(szDriver,
			(PULARGE_INTEGER)&ullFreeByte,
			(PULARGE_INTEGER)&ullTotalSpace,
			(PULARGE_INTEGER)&ullFreeSpace))
			continue;

		ullSumTotal += ullTotalSpace;
		
		ullSumFree += ullFreeByte / 1024 / 1024;
	}
	m_lpSysInfo.szTotalDiskSpace = ullSumTotal / 1024 / 1024 / 1024;
	m_lpSysInfo.szFreeDiskSpace = ullSumFree;
	//
	return &m_lpSysInfo;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -