Click here to Skip to main content
11,495,688 members (68,115 online)
Click here to Skip to main content
Add your own
alternative version

Versatile Tree Control

, 18 Feb 2013 CPOL 27K 2.9K 35
Tree control with custom checkbox with several other features.
CustomTreeCtrl.zip
CustomTreeCtrl.exe
CustomTreeCtrlCode.zip
CustomTreeCtrl
1.bmp
2.bmp
CustomTreeCtrl.aps
CustomTreeCtrl.clw
CustomTreeCtrl.dsp
CustomTreeCtrl.dsw
CustomTreeCtrl.opt
CustomTreeCtrl.plg
CustomTreeCtrl.suo
CustomTreeCtrl.vcproj.DEPIND01.nuvsoft31.user
nodrop.cur
res
bitmap1.bmp
bitmap_c.bmp
bitmap_d.bmp
bitmap_e.bmp
bitmap_f.bmp
bitmap_h.bmp
bitmap_m.bmp
bitmap_u.bmp
bmp00003.bmp
bmp00004.bmp
bmp00005.bmp
bmp00006.bmp
bmp00007.bmp
bmp00008.bmp
bmp00009.bmp
bmp00010.bmp
CustomTreeCtrl.ico
icon1.ico
// CustomTreeCtrlDlg.cpp : implementation file
//

#include "stdafx.h"
#include "CustomTreeCtrl.h"
#include "CustomTreeCtrlDlg.h"
#include "CItemNameDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

#define NMEMBERSTAMPPROJ 4
#define NMEMBERCASTPROJ  3

__PROJECTMEMBER::~__PROJECTMEMBER()
{
	delete m_pCustomData;
	m_pCustomData = NULL;

}
__PROJECTLEAD::~__PROJECTLEAD()
{
	delete m_pCustomData;
	m_pCustomData = NULL;


	delete[] m_projMembers;
	m_projMembers = NULL;
	
}
__PROJECT::~__PROJECT()
{
	delete m_pCustomData;

	//Loop through the project leads and delete the custom data
	delete m_projLead;
	m_projLead = NULL;

	m_pCustomData = NULL;

}


/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

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

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

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

CCustomTreeCtrlDlg::CCustomTreeCtrlDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CCustomTreeCtrlDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CCustomTreeCtrlDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

CCustomTreeCtrlDlg::~CCustomTreeCtrlDlg()
{
	if( m_pGeForceProject )
		delete m_pGeForceProject;

	if( m_pQuadroProject )
		delete m_pQuadroProject;
}

void CCustomTreeCtrlDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CCustomTreeCtrlDlg)
	DDX_Control(pDX, IDC_TREE_PROJECT, m_ctrlTree);
	DDX_Control(pDX, IDC_LIST_SELECTED, m_ctrlListSelected);
	DDX_Control(pDX, IDC_LIST_CHECKED, m_ctrlLstChecked);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CCustomTreeCtrlDlg, CDialog)
	//{{AFX_MSG_MAP(CCustomTreeCtrlDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_MESSAGE( TVN_SELECTION_CHANGED,OnTreeSelectionChanged )
	ON_MESSAGE( TVN_ITEM_CHECK_TOGGLE,OnTreeItemChecked )	
	ON_COMMAND(IDM_BOLDITEM, OnBolditem)
	ON_COMMAND(IDM_NORMALITEM, OnNormalItem)
	ON_COMMAND(IDM_INSERT_AFTER, OnInsertAfter )
	ON_COMMAND(IDM_INSERT_BEFORE, OnInsertBefore)
	ON_COMMAND(IDM_COLOR, OnChangeColor )
	ON_COMMAND(IDM_DELETE, OnDelete )
	ON_COMMAND(IDM_ADDCHECKBOX,OnAddChkBox )
	ON_COMMAND(IDM_REMOVECHKBOX,OnRemoveChkBox )
	ON_COMMAND(IDM_DISABLE,OnDisable )
	ON_COMMAND(IDM_ENABLE,OnEnable )
	ON_WM_INITMENUPOPUP ()	
	ON_BN_CLICKED( IDC_EXPAND_TREE,OnExpandTree )
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CCustomTreeCtrlDlg message handlers

BOOL CCustomTreeCtrlDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
	InitializeTree();
	m_ctrlTree.SetBkColor( RGB(255,255,255) );

	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CCustomTreeCtrlDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CCustomTreeCtrlDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CCustomTreeCtrlDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CCustomTreeCtrlDlg::InitializeTree()
{

	//Insert the tree items: TV_INSERTSTRUCT is a typedef of TVINSERTSTRUCT
	CUSTOMINSERTSTRUCT tvIS;
	
	//Insert the root item
	//---------------------
		tvIS.m_tvIS.hParent			= NULL;				//As this is a root
		tvIS.m_tvIS.hInsertAfter	= TVI_ROOT;		//Root item

		//Valid members of this item are: text,image and the selected image
		tvIS.m_tvIS.item.mask		= TVIF_IMAGE | TVIF_TEXT | TVIF_SELECTEDIMAGE; 

		//Label of the item
		tvIS.m_tvIS.item.pszText	= "NVIDIA";		
	
		//Create the custom data
		PCUSTOMITEMDATA pCustomData = new CUSTOMITEMDATA;
	
		//Images representing the normal and expanded states
		pCustomData->m_uNormalImage			= IDB_BITMAP_NVIDIA;
		pCustomData->m_uExpandedImage		= IDB_BITMAP_NVIDIA;
		
		//Disable the label editing for this item
		pCustomData->m_bEditable	= false;

		//Need checkbox or not
		pCustomData->m_bChecked		= true;

		//If checkbox is needed, then state of the check box [ CHECKED/UNCHECKED]
		pCustomData->m_bCheckState	= true;

		//Color of the item
		pCustomData->m_cItemColor   = RGB(103,199,71);

		//Menu resource associated with the item
		pCustomData->m_uMenuID		= IDR_CONTEXT_MENU;

		tvIS.m_pCustomData          = pCustomData;

		//Insert the root item
		HTREEITEM hRoot;
		hRoot = m_ctrlTree.InsertItem(&tvIS);

	//Create the project members
	//--------------------------

		//STAMP
		m_pGeForceProjectMembers = new PROJECTMEMBER[NMEMBERSTAMPPROJ];
		m_pGeForceProjectMembers[0].m_sName = "Babu";
		m_pGeForceProjectMembers[1].m_sName = "Anil";
		m_pGeForceProjectMembers[2].m_sName = "Sravan";
		m_pGeForceProjectMembers[3].m_sName = "Rajesh";

		//CAST
		m_pQuadroProjectMembers = new PROJECTMEMBER[NMEMBERCASTPROJ];
		m_pQuadroProjectMembers[0].m_sName = "Vishal";
		m_pQuadroProjectMembers[1].m_sName = "Sandeep";
		m_pQuadroProjectMembers[2].m_sName = "Ganesh";
		 



	//Create the project lead
	//-----------------------
		//STAMP
		m_pGeForceProjectLead = new PROJECTLEAD;
		m_pGeForceProjectLead->m_sName = "Avinash";
		m_pGeForceProjectLead->m_nProjmembers = NMEMBERSTAMPPROJ;
		m_pGeForceProjectLead->m_projMembers = m_pGeForceProjectMembers;

		//CAST
		m_pQuadroProjectLead = new PROJECTLEAD;
		m_pQuadroProjectLead->m_sName = "Gaurang";
		m_pQuadroProjectLead->m_nProjmembers = NMEMBERCASTPROJ;
		m_pQuadroProjectLead->m_projMembers = m_pQuadroProjectMembers;


	//Create the project 
	//------------------
		//STAMP
		m_pGeForceProject	= new PROJECT;
		m_pGeForceProject->m_sTitle = "GeForce";
		m_pGeForceProject->m_nProjLeads = 1;
		m_pGeForceProject->m_projLead = m_pGeForceProjectLead;

		//CAST
		m_pQuadroProject	= new PROJECT;
		m_pQuadroProject->m_sTitle = "Quadro";
		m_pQuadroProject->m_nProjLeads = 1;
		m_pQuadroProject->m_projLead = m_pQuadroProjectLead;

		 
	//Inser the project
		InserProject( m_pQuadroProject, hRoot );
		InserProject( m_pGeForceProject, hRoot );
}
//******************************************************************************
//To inser the project into the tree
void CCustomTreeCtrlDlg::InserProject(PPROJECT pProj,HTREEITEM hRoot)
{
	if( !pProj ||  !hRoot )
		return;
		
	CUSTOMINSERTSTRUCT tvIS;

	//First Insert the project item
	//-----------------------------------------
		tvIS.m_tvIS.hParent			=	hRoot;			//As the project under the root
		tvIS.m_tvIS.hInsertAfter	=	TVI_FIRST;	

		//Valid members of this item are: text,image and the selected image
		tvIS.m_tvIS.item.mask		= TVIF_IMAGE | TVIF_TEXT | TVIF_SELECTEDIMAGE; 

		//Name of the project is the item text
		tvIS.m_tvIS.item.pszText	= (LPSTR)( (pProj->m_sTitle).operator LPCTSTR());
	
		//Create the custom data
		PCUSTOMITEMDATA pCustomData = new CUSTOMITEMDATA;
	
		//Images representing the normal and expanded
		pCustomData->m_uNormalImage			= IDB_BITMAP_FOLDER_16;
		pCustomData->m_uExpandedImage		= IDB_BITMAP_FOLDER_OPEN_16;
		
		//Enable the label editing 
		pCustomData->m_bEditable	= true;

		//Need checkbox or not
		pCustomData->m_bChecked		= true;

		//If needed state of the check box [ CHECKED/UNCHECKED]
		pCustomData->m_bCheckState	= true;

		//Item color
		pCustomData->m_cItemColor	= RGB(255,40,148);

		//Menu resource for this item
		pCustomData->m_uMenuID		= IDR_CONTEXT_MENU;

		//Custom data
		tvIS.m_pCustomData          = pCustomData;
		pProj->m_pCustomData	=	pCustomData;
		
		//Insert the project into the tree
		HTREEITEM hPRoject = m_ctrlTree.InsertItem(&tvIS);
		
	//Insert the project lead of this project
	//-----------------------------------------------------
		int i = 0;
		for( i = 0; i < pProj->m_nProjLeads; i++ )
		{
			InserProjectLead( &pProj->m_projLead[i],hPRoject);
		}
}

//******************************************************************************
//To insert the project leader
void CCustomTreeCtrlDlg::InserProjectLead(PPROJECTLEAD pProjLead,HTREEITEM hProj )
{
	if( !hProj ||  !pProjLead )
		return;

		CUSTOMINSERTSTRUCT tvIS;

	//Insert the project leader
	//-------------------------
		tvIS.m_tvIS.hParent			=	hProj;			//Item of the project is the parent for the project lead
		tvIS.m_tvIS.hInsertAfter	=	TVI_FIRST;

		//Valid members of this item are: text,image and the selected image
		tvIS.m_tvIS.item.mask		= TVIF_IMAGE | TVIF_TEXT | TVIF_SELECTEDIMAGE; 
		tvIS.m_tvIS.item.pszText	= (LPSTR)( (pProjLead->m_sName).operator LPCTSTR());
	
		//Create the custom data
		PCUSTOMITEMDATA pCustomData = new CUSTOMITEMDATA;
	
		///Images representing data
		pCustomData->m_uNormalImage			= IDB_BITMAP_MANAGER_16;
		pCustomData->m_uExpandedImage		= IDB_BITMAP_MANAGER_16;
			
		tvIS.m_pCustomData          =   pCustomData;

		//Color of the item
		pCustomData->m_cItemColor	=   RGB(0,128,255);
		pCustomData->m_bEditable = false;

		//Menu of the item
		pCustomData->m_uMenuID		= IDR_CONTEXT_MENU;

		//This item cannot be a target for the drag
		pCustomData->m_bDropTarget	= false;

		pProjLead->m_pCustomData	=	pCustomData;
		
		//Tree item of the project lead
		HTREEITEM hProjLead = m_ctrlTree.InsertItem(&tvIS);

		//Insert the project members under the project lead
		//-----------------------------------------------------------------------
		int i = 0;
		for( i = 0; i < pProjLead->m_nProjmembers; i++ )
		{
			InsertProjectMembers( &pProjLead->m_projMembers[i] ,hProjLead );
		}
	

}
//******************************************************************************
//To insert the project member
void CCustomTreeCtrlDlg::InsertProjectMembers( PPROJECTMEMBER pProjMem,HTREEITEM hProjLead )
{
	if( !pProjMem || !hProjLead )
		return;

	CUSTOMINSERTSTRUCT tvIS;

	//Insert the project leader
	//-------------------------
		tvIS.m_tvIS.hParent		=	hProjLead;		//Project lead is the parent for the member
		tvIS.m_tvIS.hInsertAfter	=	TVI_LAST;	

		//Valid members of this item are: text,image and the selected image
		tvIS.m_tvIS.item.mask		= TVIF_IMAGE | TVIF_TEXT | TVIF_SELECTEDIMAGE; 

		//Label of the item
		tvIS.m_tvIS.item.pszText	= (LPSTR)( (pProjMem->m_sName).operator LPCTSTR());

		//Create the custom data
		PCUSTOMITEMDATA pCustomData = new CUSTOMITEMDATA;
		
		//Images representing normal and expanded state
		pCustomData->m_uNormalImage			= IDB_BITMAP_HEAD_16;
		pCustomData->m_uExpandedImage		= IDB_BITMAP_HEAD_16;
		
		tvIS.m_pCustomData          = pCustomData;

		//Item color
		pCustomData->m_cItemColor	=   RGB(128,0,255);

		//Menu of the item
		pCustomData->m_uMenuID		= IDR_CONTEXT_MENU;

		pProjMem->m_pCustomData	    =	pCustomData;

		//Insert the project member
		HTREEITEM hProjMem = m_ctrlTree.InsertItem(&tvIS);	
}

//******************************************************************************
LRESULT CCustomTreeCtrlDlg::OnTreeSelectionChanged(WPARAM wparam,LPARAM lparam )
{
	vector<HTREEITEM>*	pSelArray = (vector<HTREEITEM>*)wparam;

	int iSelItemCnt = (*pSelArray).size();

	int i = 0;
	m_ctrlListSelected.ResetContent();
	for( ; i < iSelItemCnt; i++ )
	{
		HTREEITEM hItem = (*pSelArray)[i];
		CString str = m_ctrlTree.GetItemText( hItem );
		m_ctrlListSelected.AddString( str );
	}

	return 0;
}
//******************************************************************************
LRESULT CCustomTreeCtrlDlg::OnTreeItemChecked(WPARAM wparam,LPARAM lparam )
{
	set<HTREEITEM>*	pCheckedArray = (set<HTREEITEM>*)wparam;

	int iExpItemCnt = (*pCheckedArray).size();

	int i = 0;
	m_ctrlLstChecked.ResetContent();

	set<HTREEITEM>::iterator it = pCheckedArray->begin( );
	for( ; it != pCheckedArray->end( ); it++ )
	{
		HTREEITEM hItem = *it;
		CString str = m_ctrlTree.GetItemText( hItem );
		m_ctrlLstChecked.AddString( str );
	}
	
	return 0;
}



//###########################################################################
//								MENU HANDLERS
//###########################################################################

//***************************************************************************
void CCustomTreeCtrlDlg::OnBolditem() 
{
	HTREEITEM rClickItem = m_ctrlTree.m_hRClickItem;

	// TODO: Add your command handler code here
	if(rClickItem )
	{
		//Make the item as bold 
		PCUSTOMITEMDATA pCustomData  = (PCUSTOMITEMDATA) m_ctrlTree.GetItemData( rClickItem );
		
		//If the item is alreay bold dont do it
		if( pCustomData->m_bIsBold )
			return;

		pCustomData->m_bIsBold = !pCustomData->m_bIsBold;
		m_ctrlTree.Invalidate();
	}
	
}
//***************************************************************************
void CCustomTreeCtrlDlg::OnNormalItem() 
{
	HTREEITEM rClickItem = m_ctrlTree.m_hRClickItem;

	// TODO: Add your command handler code here
	if(rClickItem )
	{
		//Make the item as bold 
		PCUSTOMITEMDATA pCustomData  = (PCUSTOMITEMDATA) m_ctrlTree.GetItemData( rClickItem );
		
		//If the item is alreay bold dont do it
		if( !pCustomData->m_bIsBold )
			return;

		pCustomData->m_bIsBold = false;
		m_ctrlTree.Invalidate();
	}
	
}
//***************************************************************************
void CCustomTreeCtrlDlg::OnInsertAfter() 
{
	HTREEITEM rClickItem = m_ctrlTree.m_hRClickItem;

	// TODO: Add your command handler code here
	if( rClickItem )
	{
		//Get the item data
		PCUSTOMITEMDATA pRClickCustomData  = (PCUSTOMITEMDATA) m_ctrlTree.GetItemData( rClickItem );
		
		//Get the name of the new item
		CItemNameDlg dlg;
		if( dlg.DoModal() == IDOK )
		{
			CString sItemName = dlg.m_sItemName;

			//If the name is not empty
			if( !sItemName.IsEmpty() )
			{
				CUSTOMINSERTSTRUCT tvIS;
				tvIS.m_tvIS.hParent			= m_ctrlTree.GetParentItem( rClickItem );
				tvIS.m_tvIS.hInsertAfter	= rClickItem;	
				tvIS.m_tvIS.item.mask		= TVIF_IMAGE | TVIF_TEXT | TVIF_SELECTEDIMAGE; 
				tvIS.m_tvIS.item.pszText	= (LPSTR)sItemName.operator LPCTSTR();
				tvIS.m_pCustomData			= new CUSTOMITEMDATA(*pRClickCustomData);
				HTREEITEM hItem				= m_ctrlTree.InsertItem(&tvIS);			

			}
		}
	}
	
}

//***************************************************************************
void CCustomTreeCtrlDlg::OnInsertBefore() 
{
	HTREEITEM rClickItem = m_ctrlTree.m_hRClickItem;

	if( rClickItem )
	{
		if( m_ctrlTree.GetRootItem( )  == rClickItem )
			return;

		//Get the sibling item previous to the right clicked items
		HTREEITEM hPrevSibling = m_ctrlTree.GetPrevSiblingItem( rClickItem );

		//Get the item data
		PCUSTOMITEMDATA pRClickCustomData  = (PCUSTOMITEMDATA) m_ctrlTree.GetItemData( rClickItem );
		
		//Get the name of the new item
		CItemNameDlg dlg;
		if( dlg.DoModal() == IDOK )
		{
			CString sItemName = dlg.m_sItemName;

			//If the name is not empty
			if( !sItemName.IsEmpty() )
			{
				CUSTOMINSERTSTRUCT tvIS;
				tvIS.m_tvIS.hParent		= m_ctrlTree.GetParentItem( rClickItem );
			
				if( hPrevSibling )
					tvIS.m_tvIS.hInsertAfter	= hPrevSibling;
				else
					tvIS.m_tvIS.hInsertAfter	= TVI_FIRST;

				tvIS.m_tvIS.item.mask	= TVIF_IMAGE | TVIF_TEXT | TVIF_SELECTEDIMAGE; 
				tvIS.m_tvIS.item.pszText= (LPSTR)sItemName.operator LPCTSTR();
				tvIS.m_pCustomData		= new CUSTOMITEMDATA(*pRClickCustomData);
				HTREEITEM hItem			= m_ctrlTree.InsertItem(&tvIS);			

			}
		}
	}
}
//***************************************************************************
void CCustomTreeCtrlDlg::OnChangeColor() 
{
	HTREEITEM rClickItem = m_ctrlTree.m_hRClickItem;

	CColorDialog dlg;
	if( dlg.DoModal() ==IDOK )
	{
		//Get the color from the color dlg
		COLORREF col = dlg.GetColor();
		m_ctrlTree.SetItemColor( rClickItem,col );
		m_ctrlTree.Invalidate();
	}
}
//***************************************************************************
void CCustomTreeCtrlDlg::OnDelete() 
{
	HTREEITEM rClickItem = m_ctrlTree.m_hRClickItem;
	m_ctrlTree.DeleteItem( rClickItem );	
}
//***************************************************************************
void CCustomTreeCtrlDlg::OnAddChkBox()
{
	HTREEITEM rClickItem = m_ctrlTree.m_hRClickItem;
	if( rClickItem )
	{
		m_ctrlTree.SetCheckBox( rClickItem, true );	
	}
}
//***************************************************************************
void CCustomTreeCtrlDlg::OnRemoveChkBox()
{
	HTREEITEM rClickItem = m_ctrlTree.m_hRClickItem;
	if( rClickItem )
	{
		m_ctrlTree.SetCheckBox( rClickItem, false );
	}
}
//***************************************************************************
void CCustomTreeCtrlDlg::OnDisable()
{
	HTREEITEM rClickItem = m_ctrlTree.m_hRClickItem;
	//m_ctrlTree.BackupState();
	if( rClickItem )
	{
		m_ctrlTree.EnableItem( rClickItem, false );
	}
}
//***************************************************************************
void CCustomTreeCtrlDlg::OnEnable()
{
	HTREEITEM rClickItem = m_ctrlTree.m_hRClickItem;
	//m_ctrlTree.RestoreState();
	if( rClickItem )
	{
		m_ctrlTree.EnableItem( rClickItem, true );
	}
}
//***************************************************************************
void CCustomTreeCtrlDlg::OnInitMenuPopup(CMenu* pMenu, UINT nIndex, BOOL bSysMenu) 
{
	if( !bSysMenu )
	{
		HTREEITEM rClickItem = m_ctrlTree.m_hRClickItem;
		PCUSTOMITEMDATA pRClickCustomData  = (PCUSTOMITEMDATA) m_ctrlTree.GetItemData( rClickItem );
		if( !pRClickCustomData )
			return;

		//Check the state of the item [NORMAL/BOLD ]
		if( pRClickCustomData->m_bIsBold )
			pMenu->ModifyMenu( IDM_BOLDITEM,MF_STRING | MF_BYCOMMAND,IDM_NORMALITEM,"Normal");
		else
			pMenu->ModifyMenu( IDM_NORMALITEM,MF_STRING | IDM_BOLDITEM,IDM_NORMALITEM,"Bold");


		//Check the state of the item whether its checked already
		if( pRClickCustomData->m_bChecked )
			pMenu->ModifyMenu( IDM_ADDCHECKBOX,MF_STRING | MF_BYCOMMAND,IDM_REMOVECHKBOX,"Remove Chbox");
		else
			pMenu->ModifyMenu( IDM_REMOVECHKBOX,MF_STRING | MF_BYCOMMAND,IDM_ADDCHECKBOX,"Add Chbox");

		//Check the enable/disable state of the item
		if( pRClickCustomData->m_bEnable )
			pMenu->ModifyMenu( IDM_ENABLE,MF_STRING | MF_BYCOMMAND,IDM_DISABLE,"Disable");
		else
		{
			//Disable the "Add Checkbox" menu item for the disabled item
			pMenu->ModifyMenu( IDM_ADDCHECKBOX, MF_BYCOMMAND | MF_DISABLED , IDM_ADDCHECKBOX   );
			pMenu->ModifyMenu( IDM_DISABLE,MF_STRING | MF_BYCOMMAND,IDM_ENABLE,"Enable");
		}
	}
		
}

void CCustomTreeCtrlDlg::OnExpandTree( )
{
	CButton* expandButton = (CButton*) GetDlgItem( IDC_EXPAND_TREE );
	if( expandButton )
	{
		if( expandButton->GetCheck( ) )
		{
			m_ctrlTree.ExpandTree(NULL );
		}
		else
		{
			m_ctrlTree.ExpandTree(NULL ,false);
		}
	}
	
}

void CCustomTreeCtrlDlg::OnOK()
{

}

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)

Share

About the Author

Babu_Abdulsalam
Software Developer
India India
I'm working as Senior software Engineer since 7 years and interested in MFC and COM programming.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150520.1 | Last Updated 19 Feb 2013
Article Copyright 2013 by Babu_Abdulsalam
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid