请问如何用VC程序判断所用硬盘存储空间已满?谢谢您的指点!

jsfun 2004-08-06 05:07:51
我在做一个项目的过程中遇到了这样一个问题,望高手指点一下,谢谢您!
问题一:当我的计算机中只有一个硬盘时,由于不断有数据写入硬盘,如何利用VC程序监控硬盘是否已存满?如果硬盘已存满,就弹出一个对话框或者其它有效方法提示我硬盘已满!
问题二:当计算机中不只一个主硬盘(装有我运行的操作系统的硬盘)时,还有其它硬盘,优盘,移动硬盘等其它存储设备时,由于不断有数据写入这些其它存储设备,现在我不需要判断主硬盘是否存储已满,而是需要判断其它存储设备是否存储已满!举个例子,假设我的计算机中有一个主硬盘和一个重硬盘,主硬盘装有我运行的系统,而重硬盘用于存储数据(也可以是移动硬盘或优盘),由于不断的有数据存入重硬盘,当重硬盘存储已满后,就弹出一个对话框或者其它有效方法提示我存储已满!
以上两个问题望相关高手帮帮忙,每个问题50分,见答给分,请给出VC程序代码!谢谢您!
...全文
285 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
freeinsky 2004-08-08
  • 打赏
  • 举报
回复
楼上的太强了。你做的程序有可能天天盯着电脑吗
mage1982 2004-08-07
  • 打赏
  • 举报
回复
听我的:

你坚持读写硬盘,当windows右下脚出现一个硬盘图标并出现中文提示:"硬盘空间不足"时,便可以确定了.


一定要给我分啊!!!!
听我的连代码都不用编!!!
howtotell 2004-08-07
  • 打赏
  • 举报
回复
/*
函数:取得磁盘空间信息
*/
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,§or,&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);

}
lkcowboy 2004-08-07
  • 打赏
  • 举报
回复
学习
NeoBean 2004-08-06
  • 打赏
  • 举报
回复
WMI肯定可以搞定的。详细介绍查看msdn
flyelf 2004-08-06
  • 打赏
  • 举报
回复
GetDiskFreeSpace在硬盘大于2g的时候可能会失败,所以推荐使用GetDiskFreeSpaceEx
lixiaosan 2004-08-06
  • 打赏
  • 举报
回复
楼上的两位同志动作真快。。。
GetDiskFreeSpace
GetDiskFreeSpaceEx

参数使用看msdn了
bestbear 2004-08-06
  • 打赏
  • 举报
回复
mark
holyeagle 2004-08-06
  • 打赏
  • 举报
回复
pGetDiskFreeSpaceEx = GetProcAddress( GetModuleHandle("kernel32.dll"),
"GetDiskFreeSpaceExA");

if (pGetDiskFreeSpaceEx)
{
fResult = pGetDiskFreeSpaceEx (pszDrive,
(PULARGE_INTEGER)&i64FreeBytesToCaller,
(PULARGE_INTEGER)&i64TotalBytes,
(PULARGE_INTEGER)&i64FreeBytes);

// Process GetDiskFreeSpaceEx results.
}

else
{
fResult = GetDiskFreeSpace (pszDrive,
&dwSectPerClust,
&dwBytesPerSect,
&dwFreeClusters,
&dwTotalClusters)

// Process GetDiskFreeSpace results.

}

msdn有相关的例子
快乐鹦鹉 2004-08-06
  • 打赏
  • 举报
回复
检查磁盘容量的函数是:
BOOL GetDiskFreeSpace(
LPCTSTR lpRootPathName, // root path
LPDWORD lpSectorsPerCluster, // sectors per cluster
LPDWORD lpBytesPerSector, // bytes per sector
LPDWORD lpNumberOfFreeClusters, // free clusters
LPDWORD lpTotalNumberOfClusters // total clusters
);
lpRootPathName 磁盘根路径名 例如"C:\\"
lpNumberOfFreeClusters 就是可供用户使用的簇数
=======================
Parameters
lpRootPathName
[in] Pointer to a null-terminated string that specifies the root directory of the disk to return information about. If lpRootPathName is NULL, the function uses the root of the current directory. If this parameter is a UNC name, you must follow it with a trailing backslash. For example, you would specify \\MyServer\MyShare as \\MyServer\MyShare\. However, a drive specification such as "C:" cannot have a trailing backslash.
Windows 95: The initial release of Windows 95 does not support UNC paths for the lpszRootPathName parameter. To query the free disk space using a UNC path, temporarily map the UNC path to a drive letter, query the free disk space on the drive, then remove the temporary mapping. Windows 95 OSR2 and later: UNC paths are supported.

lpSectorsPerCluster
[out] Pointer to a variable for the number of sectors per cluster.
lpBytesPerSector
[out] Pointer to a variable for the number of bytes per sector.
lpNumberOfFreeClusters
[out] Pointer to a variable for the total number of free clusters on the disk that are available to the user associated with the calling thread.
Windows 2000: If per-user disk quotas are in use, this value may be less than the total number of free clusters on the disk.

lpTotalNumberOfClusters
[out] Pointer to a variable for the total number of clusters on the disk that are available to the user associated with the calling thread.
Windows 2000: If per-user disk quotas are in use, this value may be less than the total number of clusters on the disk.
Kudeet 2004-08-06
  • 打赏
  • 举报
回复
ULARGE_INTEGER ulAvailable, ulTotal, ulFree;
GetDiskFreeSpaceEx((LPCTSTR)m_strDriver, &ulAvailable, &ulTotal, &ulFree);

16,466

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧