Click here to Skip to main content
15,892,927 members
Articles / Desktop Programming / MFC

Disk Usage Viewer

Rate me:
Please Sign up or sign in to vote.
4.63/5 (17 votes)
3 Oct 2006CPOL2 min read 78.8K   2.5K   48  
A disk usage viewer with tree-view output.
// DiskUseView.h : interface of the CDiskUseView class
//
/////////////////////////////////////////////////////////////////////////////

#if !defined(AFX_DISKUSEVIEW_H__3CF3CFA2_1B81_4502_9956_CCFACB27DF60__INCLUDED_)
#define AFX_DISKUSEVIEW_H__3CF3CFA2_1B81_4502_9956_CCFACB27DF60__INCLUDED_

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

#define MAX_LEVELS 256

class CDiskUseView : public CTreeView
{
protected: // create from serialization only
	CDiskUseView();
	DECLARE_DYNCREATE(CDiskUseView)

// Attributes
public:
	CDiskUseDoc* GetDocument();

// Operations
public:
	// these are the outwardly visible operations:
	// scan the directory and display the use tree
	unsigned __int64 DoScan(const char *pszPath);
	// expand the tree to the spec'd number of levels
	void ExpandTree(int nLevels);
	// copy a text representation of the tree to a string or a file
	void DisplayTree(CString *pCs, FILE *fp);
	// copy the path to the selected tree node
	void GetTreeNodePath(CString *pCs);

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CDiskUseView)
	public:
	virtual void OnDraw(CDC* pDC);  // overridden to draw this view
	virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
	protected:
	virtual void OnInitialUpdate(); // called first time after construct
	//}}AFX_VIRTUAL

// Implementation
public:
	virtual ~CDiskUseView();
#ifdef _DEBUG
	virtual void AssertValid() const;
	virtual void Dump(CDumpContext& dc) const;
#endif

protected:
	unsigned __int64 ScanDirectory(HTREEITEM hDir, const char *pszPath);
	void DisplaySubtree(HTREEITEM hItem, int nLevel, CString *pCs, FILE *fp);
	void ExpandTreeLevel(HTREEITEM hLevel, int nLevel);

	CString m_csPathRoot;
	bool m_bMoreThisLevel[MAX_LEVELS];

// Generated message map functions
protected:
	//{{AFX_MSG(CDiskUseView)
		// NOTE - the ClassWizard will add and remove member functions here.
		//    DO NOT EDIT what you see in these blocks of generated code !
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

#ifndef _DEBUG  // debug version in DiskUseView.cpp
inline CDiskUseDoc* CDiskUseView::GetDocument()
   { return (CDiskUseDoc*)m_pDocument; }
#endif

/////////////////////////////////////////////////////////////////////////////

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

#endif // !defined(AFX_DISKUSEVIEW_H__3CF3CFA2_1B81_4502_9956_CCFACB27DF60__INCLUDED_)

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
United States United States
Electrical engineer turned software engineer, now active in high-speed fiber-optic communications after a long career in automated test equipment development and sonar system development. Enjoy partitioning hardware/software systems into logical, coherent structures. Incorrigible builder of tools.

Comments and Discussions