取系统信息

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

/
//多媒体操作支持
#include "mmsystem.h"
/
//取磁盘空间函数支持
#include "dos.h"
#include "direct.h"
/
//取网卡Mac地址支持
#include "nb30.h"
#pragma comment(lib,"Netapi32.lib")
/
//取进程列表支持
#include <tlhelp32.h>
#include "icmp.h"

extern CString RemoteIP;        //全局变量:客户机地址

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

/*
构造函数
*/
CSystemInfo::CSystemInfo()
{
 ip=new char[128];
 user=new char[128];
 cpu=new char[128];
 os=new char[128];
 mem=new char[128];
 mac=new char[128];
 mmd=new char[128];
 mon=new char[128];
 drv=new char[128];
 drvLi=new char[128];
 
 resolution=new char[2048];
 
 GetMacAddr();
 GetMemory();
 GetDisk();
 GetMMD();
 GetMonitor();
 GetOS();
 GetCpu();
 GetUser();
 GetDrvList();
 GetResolutionList();
}


/*
析构函数
*/
CSystemInfo::~CSystemInfo()
{
    delete [] ip;
 delete [] user;
 delete [] cpu;
 delete [] os;
 delete [] mem;
 delete [] mac;
 delete [] mmd;
 delete [] mon;
 delete [] drv;
 delete [] drvLi;
 delete [] resolution;
}


/*
函数:取得CPU信息
*/
void CSystemInfo::GetCpu()
{  
 CString m_strCpuInfo;
 m_strCpuInfo.Empty();
 char OEMString[13];
 
 int iEAXValue,iEBXValue,iECXValue,iEDXValue;
 
 _asm {
  mov eax,0
   cpuid
   mov DWORD PTR OEMString,ebx
   mov DWORD PTR OEMString+4,edx
   mov DWORD PTR OEMString+8,ecx
   mov BYTE PTR OEMString+12,0
 }
 
    m_strCpuInfo.Format("%s",OEMString);
   
    _asm {
     mov eax,1
      cpuid
      mov iEAXValue,eax
      mov iEBXValue,ebx
      mov iECXValue,ecx
      mov iEDXValue,edx
    }
   
    if(iEDXValue&0x800000)
    {
     m_strCpuInfo+=" MMX Support";
    }
    else
    {
     m_strCpuInfo+=" No MMX Support";
    }
    int iCPUFamily=(0xf00 & iEAXValue)>>8;
   
    CString m_family;
    m_family.Format("%s%d","/r/n Family: ",iCPUFamily);
    m_strCpuInfo+=m_family;
   
    CString Frequency;
    _int64 start=Count();
    Sleep(1000);
    _int64 stop=Count();
    UINT cpuspeed = (UINT)((stop-start)/1000000);
    Frequency.Format("%d MHZ",cpuspeed);
    CString cpuinfo;
    cpuinfo.Format("%s%s","频率:  ",Frequency);
    m_strCpuInfo+=cpuinfo;
    strcpy(cpu,m_strCpuInfo);
   
}

/*
函数:取得多媒体设备信息
*/
void CSystemInfo::GetMMD()
{
 int wavedevice,mididevice;
    CString mmSys;
    WAVEOUTCAPS wavecap;
    MIDIOUTCAPS midicap;
    wavedevice=(int)waveOutGetNumDevs();
    mididevice=(int)midiOutGetNumDevs();
    if(wavedevice==0)
    {
     mmSys="没有发现波形设备";
    }
    else
    {
     waveOutGetDevCaps(0,&wavecap,sizeof(WAVEOUTCAPS));
     mmSys+="   波形设备:";
     mmSys+=CString(wavecap.szPname);
    }
   
    if(mididevice==0)
    {
     mmSys+="没有发现MIDI设备";
    }
    else
    {
     midiOutGetDevCaps(0,&midicap,sizeof(MIDIOUTCAPS));
     mmSys+="   MIDI设备: ";
     mmSys+=(CString)midicap.szPname;
    }
   
    strcpy(mmd,mmSys);
   
}

/*
函数:取得磁盘空间信息
*/
void CSystemInfo::GetDisk()
{
 
     CString strFreeDiskSpace;
   
    struct _diskfree_t diskfree;
    int nDrive = _getdrive();
   
    while(_getdiskfree(nDrive, &diskfree)==0)
    {
     nDrive++;
    }
    nDrive--;
    CString m_DiskSpace;
    m_DiskSpace.Empty();
   
    for(int di=2;di<nDrive;di++)
    { 
     CString mod;
     CString mod2;
     mod=di+_T('A');
     mod2.Format("%s",mod);
     mod+="://";
     DWORD sector,byte,cluster,free;
     DWORD freespace=0;
     DWORD totalspace=0;
     GetDiskFreeSpace(mod,&sector,&byte,&free,&cluster);
       
     totalspace=(cluster)*(byte);
     totalspace/=(1024*1024);
     totalspace*=sector;
    
     freespace=(free)*(byte);
     freespace/=(1024*1024);
     freespace*=sector;
    
     CString diskspace;
     diskspace.Format("%s %d/%d  MB  /r/n",mod2,freespace,totalspace);
     m_DiskSpace+=diskspace;
    }
    strcpy(drv,m_DiskSpace);
 
}


/*
函数:取得驱动器列表
*/
void CSystemInfo::GetDrvList()
{
 CString m_stDriver;
 char volname[255],filename[100];
 DWORD sno,maxl,fileflag;
 char sTmp[1];
 memset(sTmp,0,4);
 sprintf(sTmp,"%s","A://");
 for (int drv='A';drv<='Z';drv++)
 {
  sTmp[0] = (char)drv;
  if (GetDriveType(sTmp) == 3) 
  { 
   CString dr;
   dr.Format("%s%s",sTmp,"#");
   m_stDriver+=dr;
  }
  if (GetDriveType(sTmp) == 5) 
  {
   if(GetVolumeInformation(sTmp,volname,255,&sno,&maxl,&fileflag,filename,100))
   {
    CString dr;
    dr.Format("%s%s",sTmp,"#");
    m_stDriver+=dr;
   }
   m_cd=drv;
  }
 }
 strcpy(drvLi,m_stDriver);
}

/*
函数:取得CPU启动到现在运行的周期数
*/
_int64 CSystemInfo::Count(void)
{
 _asm
 {
  _emit 0x0F
  _emit 0x31
 }
 
}

/*
函数:取得内存信息
*/
void CSystemInfo::GetMemory()
{
    CString strFreeMemory;
    CString strFmt;
   
    // Fill available memory
    MEMORYSTATUS MemStat;
    MemStat.dwLength = sizeof(MEMORYSTATUS);
    GlobalMemoryStatus(&MemStat);
    int m_Mem;
    m_Mem=MemStat.dwTotalPhys / 1024L;
    m_Mem/=1024;
   
    CString strM;
    strM.Format("  %d MB",m_Mem);
    strcpy(mem,strM);   
}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值