forked from GLDsuh-a/qt-1
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add get cpu、 ram、 disk information demo
- Loading branch information
litz-a
committed
Jan 15, 2016
1 parent
bbfdce4
commit 73df737
Showing
10 changed files
with
1,679 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.