04-29 02:46
Notice
Recent Posts
Recent Comments
관리 메뉴

Scientific Computing & Data Science

[C/C++] MFC / 디스크 공간 정보 출력하기 본문

Programming/C&C++

[C/C++] MFC / 디스크 공간 정보 출력하기

cinema4dr12 2014. 6. 24. 18:05

[Source Code]

* 샘플 코드 다운로드: http://www.gchoi.net/temp/DiskSpace.zip

* 개발환경: Visual Studio 2012


GetDiskFreeSpaceEx 함수를 이용하여 자신의 컴픁의 디스크 공간에 대한 정보를 출력하는 코드는 다음과 같다:



ULARGE_INTEGER avail, total, free;
avail.QuadPart = 0L;
total.QuadPart = 0L;
free.QuadPart = 0L;

int m_avail, m_total, m_free;

CString strMsg;

////////// Drive C
// C:\의 하드디스크 용량 정보를 받아 옴
GetDiskFreeSpaceEx(TEXT("c:\\"), &avail, &total, &free);

// GByte 로 표현을 하기 위한 부분
m_total = (int)(total.QuadPart>>30);
m_free = (int)(free.QuadPart>>30);

// Print out
strMsg.Format(_T("C: Total Size: %d GB , Free Size : %d GB\n"), m_total, m_free);

////////// Drive D
// D:\의 하드디스크 용량 정보를 받아 옴
GetDiskFreeSpaceEx(TEXT("d:\\"), &avail, &total, &free);

// GByte 로 표현을 하기 위한 부분
m_total = (int)(total.QuadPart>>30);
m_free = (int)(free.QuadPart>>30);

// Print out information of disks
strMsg.Format(strMsg + _T("D: Total Size: %d GB , Free Size : %d GB\n"), m_total, m_free);
AfxMessageBox(strMsg);


[실행 예]

다음 실행 프로그램에서 "" 버튼 클릭


다음 그림과 같이 C와 D 드라이브의 전체 공간 및 여유 공간을 표시한다.



Comments