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

Task Manager Extension 2.0

Rate me:
Please Sign up or sign in to vote.
4.92/5 (149 votes)
22 Jan 2007CDDL11 min read 598.1K   18.7K   263  
Task Manager Extension. This is a Windows Task Manager (NT/2000/XP/2003) plug-in. It adds lots of useful features to the standard Task Manager. It can show process modules, memory map, used handles, open files, file properties and a lot of other info!
#if !defined(AFX_CSystemInfoListCtrl_H__CFA0E206_B822_4A36_91B8_55129F335FB5__INCLUDED_)
#define AFX_CSystemInfoListCtrl_H__CFA0E206_B822_4A36_91B8_55129F335FB5__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// CSystemInfoListCtrl.h : header file
//

class CSortClass;

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

#define MINIMAL_COLUMN_WIDTH	30
#define DEFAULT_COLUMN_WIDTH	60

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

#define LIST_IMAGE_WIDTH		1

/////////////////////////////////////////////////////////////////////////////
// CSystemInfoListCtrl window

class CSystemInfoListCtrl : public CListCtrl
{
// Construction
public:
	CSystemInfoListCtrl();

// Attributes
public:

// Operations
public:
	//BOOL SortTextItems( int nCol, BOOL bAscending, int low = 0, int high = -1 );
	BOOL GetSubItemText( int, LPCTSTR, CString& );
	int GetSelectedItem();
	void SetSelectedItem( int nItem );
	BOOL GetSelectedSubItemText( int, CString& );
	BOOL GetSelectedSubItemText( LPCTSTR, CString& );
	int FindColumn( LPCTSTR );

	void ReSort();

	//////////////////////////////////////////////////////////////
	//  Sorting:

	void SetSortedColumn(int nCol)
	{
		m_wndHeader.SetSortedColumn( nCol );
	}

	void SetSortAscending(BOOL bAscending)
	{
		m_wndHeader.SetSortAscending( bAscending );
	}

	BOOL IsSortAscending() const
	{
		BOOL res = m_wndHeader.IsSortAscending();
		return res;
	}
	int GetSortedColumn() const
	{
		int res = m_wndHeader.GetSortedColumn();
		return res;
	}

	int InsertColumn (int nCol, LPCTSTR lpszColumnHeading, int nFormat = LVCFMT_LEFT,
		int nWidth = DEFAULT_COLUMN_WIDTH, int nSubItem = -1)
	{
		int res = CListCtrl::InsertColumn( nCol, lpszColumnHeading, nFormat, nWidth, nSubItem );
		return res;
	}

protected:

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CSystemInfoListCtrl)
	protected:
	virtual void PreSubclassWindow();
	//}}AFX_VIRTUAL

// Implementation
public:
	virtual ~CSystemInfoListCtrl();

	// Generated message map functions
protected:

	////////////////////////////////////////////////////////////////////////////////
	// The header control only used by CSystemInfoListCtrl
	////////////////////////////////////////////////////////////////////////////////
	class CReportHeaderCtrl : public CHeaderCtrl			
	{
	public:		
		CReportHeaderCtrl();
		virtual ~CReportHeaderCtrl() {};	
		void SetSortedColumn(int nCol);
		void SetSortAscending(BOOL bAscending);
		BOOL IsSortAscending() const;
		int GetSortedColumn() const;
		void UpdateSortArrow();

	protected:
		void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
		int m_iSortColumn;
		BOOL m_bSortAscending;
	};

	// Member data
	CReportHeaderCtrl m_wndHeader;
	
	//{{AFX_MSG(CSystemInfoListCtrl)
	afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
	afx_msg void OnContextMenu(CWnd* pWnd, CPoint point);
	afx_msg void OnPaint();
	afx_msg void OnSize(UINT nType, int cx, int cy);
	//}}AFX_MSG
	afx_msg void OnHeaderClicked(NMHDR*, LRESULT* );

	DECLARE_MESSAGE_MAP()
};


// Sorter
class CSortClass
{
public:
	CSortClass(CListCtrl * _pWnd, const int _iCol, const bool _bIsNumeric);
	virtual ~CSortClass();
	
	int iCol;
	CListCtrl * pWnd;
	bool bIsNumeric;
	void Sort(const bool bAsc);
	
	static int CALLBACK CompareAsc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort);
	static int CALLBACK CompareDes(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort);
	
	static int CALLBACK CompareAscI(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort);
	static int CALLBACK CompareDesI(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort);
	
public:
	class CSortItem
	{
	public:
		virtual  ~CSortItem();
		CSortItem(DWORD _dw, int indent, const CString &_txt);
		CString	txt;	// item text
		int		indent;	// item indent
		DWORD	dw;		// old user item User Data
	};
	class CSortItemInt
	{
	public:
		CSortItemInt(DWORD _dw, int indent, const CString &_txt);
		int		iInt;	// item value
		int		indent;	// item indent
		DWORD	dw;		// old user item User Data
	};
};

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

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

#endif // !defined(AFX_CSystemInfoListCtrl_H__CFA0E206_B822_4A36_91B8_55129F335FB5__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 Common Development and Distribution License (CDDL)


Written By
Software Developer (Senior)
Belarus Belarus
He is a young and forward-looking software developer. He also has lots of interesting hobbies like snowboarding, bicycle riding, carting racing and of course talking about himself in a third person. Smile | :)

github.com/kolomenkin

Curriculum Vitae

Comments and Discussions