Click here to Skip to main content
12,883,390 members (39,267 online)
Click here to Skip to main content
Add your own
alternative version


42 bookmarked
Posted 8 Feb 2003

Drive Information

, 8 Feb 2003
Rate this:
Please Sign up or sign in to vote.
A CStatic derived class to show drive information.
<!-- Download Links --> <!-- Article image -->

Sample Image - DriveInfo.jpg

<!-- Add the rest of your HTML here -->


All of us know that a very simple chart or an image can transfer more valuable information than a table or text to memory. Because of this, we use charts and images when we have complex set of data and informations.

I used this rule, to create a static derived class to show drive information in a visual manner. This class shows capacity of disk, used and free space of it with a simple pie chart.

Note: Part of code to draw pie chart was taken from article "Chart and Pie for data with hole" written by Tingshao Zhu

How to use

First add DriveInfo.h and DriveInfo.cpp files to your project. Then in your dialog resource editor, add new Static control (figure 2 shows it). Rename this static control ID to your desired ID, for example IDC_DRIVE_INFO (like figure 3). Run class wizard (Ctrl+W) and add new member variable with variable type CStatic (you must choose Control in category combo box). Named it as m_Drive. Figure 4 shows you how declare a new CStatic control.

Static control
Figure 2- Add new static control to dialog resource

Figure 3- Change ID of static control from IDC_STATIC to IDC_DRIVE_INFO

Add member variable
Figure 4- Add member variable with variable type CStatic

OK. Now in your dialog header file, change this line:

CStatic m_Drive;
CDriveInfo m_Drive;
Don't forget to include DriveInfo.h header file on top of your dialog class definition. Now your dialog definition looks like this:
// DriveInfoDlg.h : header file


#if !defined(AFX_DRIVEINFODLG_H__505181DF_1106_4370_8526_77AED93D4F5E__INCLUDED_)
#define AFX_DRIVEINFODLG_H__505181DF_1106_4370_8526_77AED93D4F5E__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "DriveInfo.h"
// CDriveInfoDlg dialog

class CDriveInfoDlg : public CDialog
// Construction

    CDriveInfoDlg(CWnd* pParent = NULL);    // standard constructor

// Dialog Data


    CDriveInfo    m_Drive;    //Changed from CStatic


    // ClassWizard generated virtual function overrides


    virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support


// Implementation

    HICON m_hIcon;

    // Generated message map functions


    virtual BOOL OnInitDialog();
    afx_msg void OnPaint();
    afx_msg HCURSOR OnQueryDragIcon();



// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_DRIVEINFODLG_H__505181DF_1106_4370_8526_77AED93D4F5E__INCLUDED_)

CDriveInfo class

CDriveInfo class has only two member function. Each of these member functions used to displayed information of desired drive.

void SetDriveLetter(LPCSTR szDriveLetter);
SetDriveLetter takes only one parameter, drive letter. For showing information of your desired drive, only pass drive letter of it. For example:


will show statistics of drive C.

void SetDriveNumber(UINT iDriveNum);
If you don't know drive letter of specified disk, use this function. Just pass drive number and CDriveInfo will show drive information. For example:


will show informatoin of drive A.



This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

A. Riazi
CEO Misbah3Com
Iran (Islamic Republic of) Iran (Islamic Republic of)
I was born in Shiraz, a very beautiful famous city in Iran. I started programming when I was 12 years old with GWBASIC. Since now, I worked with various programming languages from Basic, Foxpro, C/C++, Visual Basic, Pascal to MATLAB and now Visual C++.
I graduated from Iran University of Science & Technology in Communication Eng., and now work as a system programmer for a telecommunication industry.
I wrote several programs and drivers for Synthesizers, Power Amplifiers, GPIB, GPS devices, Radio cards, Data Acqusition cards and so many related devices.
I'm author of several books like Learning C (primary and advanced), Learning Visual Basic, API application for VB, Teach Yourself Object Oriented Programming (OOP) and etc.
I'm winner of January, May, August 2003 and April 2005 best article of month competetion, my articles are:

You can see list of my articles, by clicking here

You may also be interested in...

Comments and Discussions

GeneralMy vote of 5 Pin
manoj kumar choubey26-Feb-12 19:48
membermanoj kumar choubey26-Feb-12 19:48 
Question2Tb Virtual Disk Pin
nhchmg27-Jun-11 20:26
membernhchmg27-Jun-11 20:26 
QuestionHard Drive Letter Assignment Pin
Member #38930658-Mar-07 2:10
memberMember #38930658-Mar-07 2:10 
GeneralDisplaying drive Type Pin
jcynion25-Apr-04 19:12
memberjcynion25-Apr-04 19:12 
GeneralRe: Displaying drive Type Pin
Anonymous26-Apr-04 3:45
sussAnonymous26-Apr-04 3:45 
GeneralRe: Displaying drive Type Pin
nackterkofferpacker16-Oct-07 3:51
membernackterkofferpacker16-Oct-07 3:51 
GeneralI'm Iranian too! Pin
mhr t15-Jul-03 10:35
membermhr t15-Jul-03 10:35 
GeneralRe: I'm Iranian too! Pin
Koundinya22-Apr-04 3:10
memberKoundinya22-Apr-04 3:10 
GeneralRe: I'm Iranian too! Pin
Wamuti6-Jul-07 6:57
memberWamuti6-Jul-07 6:57 
Generalmb Pin
mb0676-Jul-03 18:00
sussmb0676-Jul-03 18:00 
GeneralI improoved the ctrl a bit: Pin
HackMan19-May-03 3:18
memberHackMan19-May-03 3:18 
GeneralRe: I improoved the ctrl a bit: Pin
A. Riazi19-May-03 19:04
memberA. Riazi19-May-03 19:04 
GeneralNice Pin
Jeff J9-Feb-03 8:55
memberJeff J9-Feb-03 8:55 
GeneralRe: Nice Pin
A. Riazi10-Feb-03 6:11
memberA. Riazi10-Feb-03 6:11 
GeneralErrors on compailing Pin
Peppe9-Feb-03 6:24
memberPeppe9-Feb-03 6:24 
GeneralRe: Errors on compailing Pin
A. Riazi10-Feb-03 6:14
memberA. Riazi10-Feb-03 6:14 
GeneralRe: Errors on compailing Pin
Peppe10-Feb-03 7:41
memberPeppe10-Feb-03 7:41 
GeneralRe: Errors on compailing Pin
A. Riazi10-Feb-03 20:02
memberA. Riazi10-Feb-03 20:02 
GeneralRe: Errors on compailing Pin
Peppe11-Feb-03 2:52
memberPeppe11-Feb-03 2:52 
GeneralWell done Pin
Bitterman9-Feb-03 5:39
memberBitterman9-Feb-03 5:39 
GeneralRe: Well done Pin
A. Riazi10-Feb-03 6:05
memberA. Riazi10-Feb-03 6:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170422.1 | Last Updated 9 Feb 2003
Article Copyright 2003 by A. Riazi
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid