Skip to content

Commit

Permalink
add get cpu、 ram、 disk information demo
Browse files Browse the repository at this point in the history
  • Loading branch information
litz-a committed Jan 15, 2016
1 parent bbfdce4 commit 73df737
Show file tree
Hide file tree
Showing 10 changed files with 1,679 additions and 0 deletions.
443 changes: 443 additions & 0 deletions GLDUserInfoUtils/GLDDiskInfoUtils.cpp

Large diffs are not rendered by default.

91 changes: 91 additions & 0 deletions GLDUserInfoUtils/GLDDiskInfoUtils.h
Original file line number Diff line number Diff line change
@@ -0,0 1,91 @@
#ifndef GLDDISKINFOUTILS_H
#define GLDDISKINFOUTILS_H

#include <qt_windows.h>
#include <bitset>
#include <iostream>
#include <algorithm>
#include <utility>
#include <Winioctl.h>
#include <string>
#include <map>
#include <QVector>
#include <QString>
#include <QHash>

using namespace std;

namespace GLDDISKINFO
{
enum FS
{
OTHER_FORMAT = 0,
FAT32 = 1,
NTFS = 2
};

typedef struct SDiskInfomation
{
SDiskInfomation()
{
m_dwFreeMBytes = 0;
m_dwTotalMBytes = 0;
}

QString m_strDiskName; // 分区名(盘符)
QString m_strTypeName; // 分区类型
QString m_strFileSystem; // 分区格式
ulong m_dwTotalMBytes; // 总空间
ulong m_dwFreeMBytes; // 可用空间

}DiskInfomation;

class GLDDiskInfo
{
public:
/**
* @brief 获取硬盘序列号
* @return
*/
QString getDiskSerialNo();

/**
* @brief 获取分区个数
* @return
*/
ulong getDriverNum();

/**
* @brief 获取所有分区信息
* @return
*/
QVector<DiskInfomation> getAllDriversInfo();

/**
* @brief 获取分区格式
* @param dir 分区名
* @return
*/
FS getFileSystemType(const QString& dir);

/**
* @brief 获取分区类型
* @param dir 分区名
* @return
*/
QString getDriverTypeItem(const QString& dir);

bool getLastVolumeInfo(DiskInfomation &diskInfo);
bool getDiskSize(quint64 &llOfSectors, ulong dwDiskNum = 0);
bool getDiskSize2(quint64 &llOfSectors, ulong dwDiskNum = 0);
bool getVolumeSize(quint64 &llOfSectors, string volName);
bool getFreeSpace(const QString& dir, qint64& ri64FreeBytesToCaller, qint64& ri64TotalBytes);

private:
bool getAllDriverName(ulong dwDrvNum, QVector<QString> & driveNameVct);
void toLittleEndian(PUSHORT pWords, int nFirstIndex, int nLastIndex, LPTSTR pBuf);
void trimStart(LPTSTR pBuf);
};
}

#endif // GLDDISKINFOUTILS_H
29 changes: 29 additions & 0 deletions GLDUserInfoUtils/GLDMemoryInfoUtils.cpp
Original file line number Diff line number Diff line change
@@ -0,0 1,29 @@
#include "GLDMemoryInfoUtils.h"

namespace GLDMemoryInfo
{
PhysMemInfo getPhysMemInfo()
{
PhysMemInfo memInfo;
MEMORYSTATUSEX mymem;
mymem.dwLength = sizeof(MEMORYSTATUSEX);
GlobalMemoryStatusEx(&mymem);
memset(&memInfo, 0, sizeof(memInfo));
memInfo.m_totalPhys = (mymem.ullTotalPhys) / 1024 / 1024;
memInfo.m_availPhys = (mymem.ullAvailPhys) / 1024 / 1024;
memInfo.m_usedPhys = mymem.dwMemoryLoad;
return memInfo;
}

VirMemInfo getVirMemInfo()
{
VirMemInfo memInfo;
MEMORYSTATUSEX mymem;
mymem.dwLength = sizeof(MEMORYSTATUSEX);
GlobalMemoryStatusEx(&mymem);
memset(&memInfo, 0, sizeof(memInfo));
memInfo.m_totalVirtual = (mymem.ullTotalVirtual) / 1024 / 1024;
memInfo.m_availVirtual = (mymem.ullAvailVirtual) / 1024 / 1024;
return memInfo;
}
}
26 changes: 26 additions & 0 deletions GLDUserInfoUtils/GLDMemoryInfoUtils.h
Original file line number Diff line number Diff line change
@@ -0,0 1,26 @@
#ifndef GLDMEMORYINFOUTILS_H
#define GLDMEMORYINFOUTILS_H

#include <windows.h>

namespace GLDMemoryInfo
{
typedef struct PhysicalMemoryInfo
{
__int64 m_totalPhys; // 总内存数,单位M
__int64 m_availPhys; // 可用内存数,单位M
int m_usedPhys; // 已用内存百分比,范围:0-100
} PhysMemInfo;

typedef struct VirtualMemoryInfo
{
__int64 m_totalVirtual; // 总虚拟内存数,单位M
__int64 m_availVirtual; // 可用虚拟内存数,单位M
} VirMemInfo;

PhysMemInfo getPhysMemInfo();

VirMemInfo getVirMemInfo();
}

#endif // GLDMEMORYINFOUTILS_H
Loading

0 comments on commit 73df737

Please sign in to comment.