磁盘的使用详情,及磁盘的总容量、剩余容量和剩余可用容量。代码如下#include windows.h#include QVectorstruct DriveInfo{QString sDriName;quint64 uiTotal;quint64 uiFree;quint64 uiFree2Caller;DriveInf...
磁盘的使用详情,及磁盘的总容量、剩余容量和剩余可用容量。
代码如下
#include <windows.h>
#include <QVector>
struct DriveInfo
{
QString sDriName;
quint64 uiTotal;
quint64 uiFree;
quint64 uiFree2Caller;
DriveInfo()
{
sDriName = "";
uiTotal = 0;
uiFree = 0;
uiFree2Caller = 0;
}
};
// 获取所有本地磁盘的使用详情
QVector<DriveInfo> SystemInfo::get_local_drive_info()
{
QVector<DriveInfo> vecDriInfo;
DWORD diskCntArr = GetLogicalDrives();
int diskCnt = 0;
while (diskCntArr)
{
if (diskCntArr & 1)
{
diskCnt++;
}
diskCntArr = diskCntArr >> 1;
}
int DSLength = GetLogicalDriveStrings(0, NULL);
TCHAR* DStr = new TCHAR[DSLength];
GetLogicalDriveStrings(DSLength, (LPTSTR)DStr);
int dri_type;
BOOL fResult;
quint64 iFree2Caller = 0;
quint64 iTotalBytes = 0;
quint64 iFreeBytes = 0;
TCHAR *lpDriveStr = DStr;
for (int i = 0; i < diskCnt; ++i)
{
dri_type = GetDriveType(lpDriveStr);
if (dri_type == DRIVE_FIXED)
{
fResult = GetDiskFreeSpaceEx(lpDriveStr, (PULARGE_INTEGER)&iFree2Caller, (PULARGE_INTEGER)&iTotalBytes, (PULARGE_INTEGER)&iFreeBytes);
if (fResult)
{
DriveInfo info;
info.sDriName = QString::fromStdWString(lpDriveStr);
info.uiFree2Caller = iFree2Caller;
info.uiTotal = iTotalBytes;
info.uiFree = iFreeBytes;
vecDriInfo << info;
}
else
{
// 打印日志 megloglib
qDebug() << "读取硬盘{0}使用情况时错误";
}
lpDriveStr += 4;
}
else
{
lpDriveStr += 4;
}
}
delete[] DStr;
DStr = NULL;
return vecDriInfo;
}
沃梦达教程
本文标题为:【Windows系统】C++ Qt方式获取所有磁盘使用详情
基础教程推荐
猜你喜欢
- 详解c# Emit技术 2023-03-25
- C++详细实现完整图书管理功能 2023-04-04
- C++使用easyX库实现三星环绕效果流程详解 2023-06-26
- C语言 structural body结构体详解用法 2022-12-06
- 如何C++使用模板特化功能 2023-03-05
- C语言基础全局变量与局部变量教程详解 2022-12-31
- C++中的atoi 函数简介 2023-01-05
- 一文带你了解C++中的字符替换方法 2023-07-20
- C/C++编程中const的使用详解 2023-03-26
- C利用语言实现数据结构之队列 2022-11-22