Click here to Skip to main content
15,897,291 members
Articles / Desktop Programming / MFC

Versatile Tree Control

Rate me:
Please Sign up or sign in to vote.
4.92/5 (16 votes)
18 Feb 2013CPOL12 min read 78.5K   5.9K   44  
Tree control with custom checkbox with several other features.
// CustomTreeCtrlDlg.h : header file
//

#if !defined(AFX_CUSTOMTREECTRLDLG_H__A9DD5E95_0B84_43F9_96D8_4B3B155A4DD8__INCLUDED_)
#define AFX_CUSTOMTREECTRLDLG_H__A9DD5E95_0B84_43F9_96D8_4B3B155A4DD8__INCLUDED_

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

#include "CCVersatileTreeCtrl.h"

//************************************************

typedef struct __PROJECTMEMBER
{
	__PROJECTMEMBER()
	{
		m_pCustomData = NULL;
	}
	~__PROJECTMEMBER();
	
	//Name of the project member
	CString  m_sName;

	//Custom data associated with the  member
	PCUSTOMITEMDATA		m_pCustomData;
	
}PROJECTMEMBER,*PPROJECTMEMBER;

//************************************************

typedef struct __PROJECTLEAD
{
	__PROJECTLEAD()
	{
		m_projMembers = NULL;
		m_pCustomData = NULL;
	}
	~__PROJECTLEAD();

	//Name of the lead
	CString m_sName;

	//Number of Project members under the lead
	int		m_nProjmembers;

	//Custom data associated with the lead
	PCUSTOMITEMDATA		m_pCustomData;

	//Project members under the lead
	PPROJECTMEMBER	m_projMembers;

}PROJECTLEAD,*PPROJECTLEAD;

//************************************************
typedef struct __PROJECT
{
	__PROJECT()
	{
		m_projLead		= NULL;
		m_pCustomData = NULL;
	}
	~__PROJECT();


	CString m_sTitle;
	int     m_nProjLeads;
	PPROJECTLEAD  m_projLead;
	PCUSTOMITEMDATA		m_pCustomData;

}PROJECT,*PPROJECT;


/////////////////////////////////////////////////////////////////////////////
// CCustomTreeCtrlDlg dialog

class CCustomTreeCtrlDlg : public CDialog
{
// Construction
public:
	CCustomTreeCtrlDlg(CWnd* pParent = NULL);	// standard constructor

	~CCustomTreeCtrlDlg();

// Dialog Data
	//{{AFX_DATA(CCustomTreeCtrlDlg)
	enum { IDD = IDD_CUSTOMTREECTRL_DIALOG };
	CVersatileTreeCtrl	m_ctrlTree;
	CListBox	m_ctrlListSelected;
	CListBox	m_ctrlLstChecked;
	//}}AFX_DATA

	//Project members working with the project leads
	PPROJECTMEMBER	m_pGeForceProjectMembers,m_pQuadroProjectMembers ;

	//Project leads of the projects
	PPROJECTLEAD	m_pGeForceProjectLead,m_pQuadroProjectLead ;

	//Project details
	PPROJECT		m_pGeForceProject,m_pQuadroProject;


	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CCustomTreeCtrlDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);	// DDX/DDV support
	//}}AFX_VIRTUAL

	void InitializeTree();

	//Insert the project
	void InserProject(PPROJECT pProj,HTREEITEM hRoot );

	//Insert the project lead
	void InserProjectLead(PPROJECTLEAD pProjLead,HTREEITEM hProj );

	//Insert the project members
	void InsertProjectMembers( PPROJECTMEMBER pProjMem,HTREEITEM hProjLead );

// Implementation
protected:
	HICON m_hIcon;

	// Generated message map functions
	//{{AFX_MSG(CCustomTreeCtrlDlg)
	virtual BOOL OnInitDialog();
	virtual void OnOK();
	afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
	afx_msg void OnPaint();
	afx_msg HCURSOR OnQueryDragIcon();
	afx_msg LRESULT OnTreeSelectionChanged(WPARAM wparam,LPARAM lparam );
	afx_msg LRESULT OnTreeItemChecked(WPARAM wparam,LPARAM lparam );		
	afx_msg void OnBolditem();
	afx_msg void OnNormalItem();
	afx_msg void OnInsertAfter();
	afx_msg void OnInsertBefore();
	afx_msg void OnChangeColor();
	afx_msg void OnDelete();
	afx_msg void OnAddChkBox();
	afx_msg void OnRemoveChkBox();
	afx_msg void OnDisable( );
	afx_msg void OnEnable( );
	afx_msg void OnInitMenuPopup(CMenu* pMenu, UINT nIndex, BOOL bSysMenu) ;	
	afx_msg void OnExpandTree( );
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

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

#endif // !defined(AFX_CUSTOMTREECTRLDLG_H__A9DD5E95_0B84_43F9_96D8_4B3B155A4DD8__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)
India India
I'm working as Senior software Engineer since 7 years and interested in MFC and COM programming.

Comments and Discussions