📄 sysinfo.cpp
字号:
// Get System Infomation
// Written by JHCC, 1996
#include "stdafx.h"
#include "SysInfo.h"
SYSTEM_INFO CSystemInformation::m_systemInfo; // struct. for hardware info.
OSVERSIONINFO CSystemInformation::m_osVer;
MEMORYSTATUS CSystemInformation::m_MemStat; // Fill available memory
CString CSystemInformation::m_pOsStr[] =
{
_T("Unknow !"),
_T("Windows 95"),
_T("Windows NT"),
_T("Win32s"),
};
CString CSystemInformation::m_pCpuTypeStr[] =
{
_T("Unknow !"),
_T("INTEL 386"),
_T("INTEL 486"),
_T("INTEL Pentium"),
_T("MIPS R4000"),
_T("ALPHA 21064"),
};
//LPCTSTR CSystemInformation::m_lpDiskUnavilable = _T("Unavailable");
CSystemInformation::CSystemInformation()
{
::GetSystemInfo(&m_systemInfo);
m_osVer.dwOSVersionInfoSize = sizeof(m_osVer);
::GetVersionEx(&m_osVer);
m_MemStat.dwLength = sizeof(m_MemStat);
::GlobalMemoryStatus(&m_MemStat);
}
DWORD CSystemInformation::GetOemId(CString& strOut, LPCTSTR lpFmt)
{
if (lpFmt != NULL)
strOut.Format(lpFmt, m_systemInfo.dwOemId);
return m_systemInfo.dwOemId;
}
DWORD CSystemInformation::GetPageSize(CString& strOut, LPCTSTR lpFmt)
{
if (lpFmt != NULL)
strOut.Format(lpFmt, m_systemInfo.dwPageSize);
return m_systemInfo.dwPageSize;
}
LPVOID CSystemInformation::GetMinAppAddress(CString& strOut, LPCTSTR lpFmt)
{
if (lpFmt != NULL)
strOut.Format(lpFmt, m_systemInfo.lpMinimumApplicationAddress);
return m_systemInfo.lpMinimumApplicationAddress;
}
LPVOID CSystemInformation::GetMaxAppAddress(CString& strOut, LPCTSTR lpFmt)
{
if (lpFmt != NULL)
strOut.Format(lpFmt, m_systemInfo.lpMaximumApplicationAddress);
return m_systemInfo.lpMaximumApplicationAddress;
}
DWORD CSystemInformation::GetActiveProcessorMask(CString& strOut, LPCTSTR lpFmt)
{
if (lpFmt != NULL)
strOut.Format(lpFmt, m_systemInfo.dwActiveProcessorMask);
return m_systemInfo.dwActiveProcessorMask;
}
DWORD CSystemInformation::GetNumberOfProcessors(CString& strOut, LPCTSTR lpFmt)
{
if (lpFmt != NULL)
strOut.Format(lpFmt, m_systemInfo.dwNumberOfProcessors);
return m_systemInfo.dwNumberOfProcessors;
}
DWORD CSystemInformation::GetProcessorType(CString& strOut, LPCTSTR lpFmt)
{
if (lpFmt != NULL)
strOut.Format(lpFmt, m_systemInfo.dwProcessorType);
return m_systemInfo.dwProcessorType;
}
DWORD CSystemInformation::GetAllocationGranularity(CString& strOut, LPCTSTR lpFmt)
{
if (lpFmt != NULL)
strOut.Format(lpFmt, m_systemInfo.dwAllocationGranularity);
return m_systemInfo.dwAllocationGranularity;
}
OS_TYPE CSystemInformation::GetOsType(CString& strOut, LPCTSTR lpFmt)
{
OS_TYPE osType = OS_UNKNOW;
switch (m_osVer.dwPlatformId)
{
case VER_PLATFORM_WIN32_WINDOWS:
osType = OS_WIN95;
break;
case VER_PLATFORM_WIN32_NT:
osType = OS_WINNT;
break;
case VER_PLATFORM_WIN32s:
osType = OS_WIN32s;
break;
}
if (lpFmt != NULL)
strOut.Format(lpFmt, m_pOsStr[osType]);
return osType;
}
CPU_TYPE CSystemInformation::GetCpuType(CString& strOut, LPCTSTR lpFmt)
{
CPU_TYPE cpuType = CPU_UNKNOW;
switch (m_systemInfo.dwProcessorType)
{
case PROCESSOR_INTEL_386:
cpuType = CPU_INTEL_386;
break;
case PROCESSOR_INTEL_486:
cpuType = CPU_INTEL_486;
break;
case PROCESSOR_INTEL_PENTIUM:
cpuType = CPU_INTEL_PENTIUM;
break;
case PROCESSOR_MIPS_R4000:
cpuType = CPU_MIPS_R4000;
break;
case PROCESSOR_ALPHA_21064:
cpuType = CPU_ALPHA_21064;
break;
}
if (lpFmt != NULL)
strOut.Format(lpFmt, m_pCpuTypeStr[cpuType]);
return cpuType;
}
DWORD CSystemInformation::GetFreeMemory(CString& strOut, LPCTSTR lpFmt)
{
DWORD nTotalPhys = m_MemStat.dwTotalPhys / 1024L;
if (lpFmt != NULL)
strOut.Format(lpFmt, nTotalPhys);
return nTotalPhys;
}
DWORD CSystemInformation::GetFreeDiskSpace(CString& strOut, LPCTSTR lpFmt)
{
TCHAR nDrive = _T('\0');
TCHAR szCurDirStr[_MAX_PATH];
if (::GetCurrentDirectory(sizeof(szCurDirStr), szCurDirStr))
if (szCurDirStr[1] == _T(':'))
nDrive = szCurDirStr[0];
DWORD SectorsPerCluster; // sectors per cluster
DWORD BytesPerSector; // bytes per sector
DWORD NumberOfFreeClusters; // address of number of free clusters
DWORD TotalNumberOfClusters; // address of total number of clusters
DWORD dwFreeSpace = 0;
if ((nDrive != _T('\0')) &&
(::GetDiskFreeSpace(NULL, &SectorsPerCluster, &BytesPerSector,
&NumberOfFreeClusters, &TotalNumberOfClusters) == TRUE))
{
dwFreeSpace =
NumberOfFreeClusters *
SectorsPerCluster *
BytesPerSector / (DWORD)1024L;
}
if (lpFmt != NULL)
{
// if (dwFreeSpace != 0)
strOut.Format(lpFmt, dwFreeSpace, nDrive);
#if 0
else
{
if (lpDiskUnavilable != NULL)
{
strOut = lpDiskUnavilable;
}
else
{
strOut = m_lpDiskUnavilable;
}
}
#endif // 0
}
return dwFreeSpace;
}
// MSDN - PRB: VC++ Debugger Won't Support Pentium-Specific Instructions
// Why can work at console but can't at GUI ???
BOOL CSystemInformation::IsPentiumCPU(void)
{
int CPUType;
_asm
{
_emit 0x0f ; CPUID (00001111 10100010) - This is a Pentium
; specific instruction which gets information on the
_emit 0xa2 ; processor. A Pentium family processor should set
; bits 11-8 of eax to 5.
mov CPUType, eax ; Move result of CPUID to CPU variable
}
CPUType = (CPUType >> 8) & 0x000F;
return CPUType == 5;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -