Introduction
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.
Figure 2- Add new static control to dialog resource
Figure 3- Change ID of static control from IDC_STATIC to IDC_DRIVE_INFO
Figure 4- Add member variable with variable type CStatic
OK. Now in your dialog header file, change this line:
CStatic m_Drive;
to
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:
#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
#include "DriveInfo.h"
class CDriveInfoDlg : public CDialog
{
public:
CDriveInfoDlg(CWnd* pParent = NULL);
enum { IDD = IDD_DRIVEINFO_DIALOG };
CDriveInfo m_Drive;
protected:
virtual void DoDataExchange(CDataExchange* pDX);
protected:
HICON m_hIcon;
virtual BOOL OnInitDialog();
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
DECLARE_MESSAGE_MAP()
};
#endif
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:
m_Drive.SetDriveLetter("c:\\");
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:
m_Drive.SetDriveNumber(0);
will show informatoin of drive A.
Enjoy!