枚举所有硬盘,可以设置枚举条件:
void emnu()
{
DWORD dwInfo = GetLogicalDrives();
int m = 0;
while(dwInfo)
{
if (dwInfo&1)
{
char ch= 'A'+m;
char chs[2] = {0};
chs[0] = ch;
int dt = GetDriveType(chs);
if (dt==DRIVE_NO_ROOT_DIR)//Åųý¹âÇý
{
//AfxMessageBox(chs);
CString str;str.Format("%d G", GetVolumelen(chs) ); AfxMessageBox(str);
}
}
dwInfo=dwInfo>>1;
m+=1;
}
}
获取指定盘符剩余空间:
long GetFreeVolumelen(char *p = "C" )
{
ULARGE_INTEGER lpuse;
ULARGE_INTEGER lptotal;
ULARGE_INTEGER lpfree;
char chvolume[10] = {0};
strcat(chvolume,p);
strcat(chvolume,":\\");
GetDiskFreeSpaceEx(/*"d:\\"*/chvolume,&lpuse,&lptotal,&lpfree);
long len = ((((lpfree.QuadPart)/1024)/1024)/1024);
return len ;
}
//
封装一个简单的类:
class Ccheckvolume
{
private:
struct tagVolumeLen
{
char volume ;
int Len ;
};
tagVolumeLen m_szVolumeLen [100];
public:
Ccheckvolume()
{
memset(m_szVolumeLen,0,sizeof(tagVolumeLen)*100 );
emnu();
}
public:
BOOL GetMaxLen(char * pchvolum = NULL, long * pLen = NULL )
{
if (pchvolum == NULL || pLen == NULL)
{
return FALSE;
}
memset(pchvolum,0,1);
memset(pLen,0,sizeof(long) );
for (int i = 0 ; i<100; i++)
{
if (m_szVolumeLen[i].volume== ' ' && m_szVolumeLen[i].Len==0 )
{
break;
}
if ( m_szVolumeLen[i].Len> *pLen)
{
memcpy(pchvolum, &(m_szVolumeLen[i].volume), 1);
memcpy(pLen, &(m_szVolumeLen[i]).Len, sizeof(long) );
}
}
return TRUE;
}
public:
long GetFreeVolumelen(char *p = "C" )
{
ULARGE_INTEGER lpuse;
ULARGE_INTEGER lptotal;
ULARGE_INTEGER lpfree;
char chvolume[10] = {0};
strcat(chvolume,p);
strcat(chvolume,":\\");
GetDiskFreeSpaceEx(/*"d:\\"*/chvolume,&lpuse,&lptotal,&lpfree);
long len = ((((lpfree.QuadPart)/1024)/1024)/1024);
return len ;
}
void emnu()
{
DWORD dwInfo = GetLogicalDrives();
int m = 0;
while(dwInfo)
{
if (dwInfo&1)
{
char ch= 'A'+m;
char chs[2] = {0};
chs[0] = ch;
int dt = GetDriveType(chs);
if (dt==DRIVE_NO_ROOT_DIR)//Åųý¹âÇý
{
//AfxMessageBox(chs);
//CString str;str.Format("%d G", GetFreeVolumelen(chs) ); AfxMessageBox(str);
if (GetFreeVolumelen(chs)>0 && GetFreeVolumelen(chs) <1000)
{
m_szVolumeLen[m].volume = chs[0];
m_szVolumeLen[m].Len = GetFreeVolumelen(chs);
}
}
}
dwInfo=dwInfo>>1;
m+=1;
}
}
};
//
void CTmfcDlg::OnButton()
{
// TODO: Add your control notification handler code here
// emnu();
Ccheckvolume ck;
char ch; long len = 0;
ck.GetMaxLen( &ch, &len);
CString str; str.Format("%c, %d", ch, len);
MessageBox(str);
}