Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Tree control templates

, 11 Jun 2001 CPOL
Three tree control templates to easily operate with CTreeCtrl derived objects
treecontroltemplates_demo.zip
PruebaPTree.aps
PruebaPTree.clw
PruebaPTree.dsp
PruebaPTree.dsw
PruebaPTree.exe
PruebaPTree.plg
res
PruebaPTree.ico
treecontroltemplates_src.zip
/////////////////////////////////////////////////////////////////////
// Template: TTCIterator
// Purpose : Template to iterate all the elements of a CTreeCtrl
//				derived object
// Created : SEN (1- Jun - 2001)
// History : None
// 
// Copyright (c) 2001 by Francisco Jos� Sen del Prado
// All rights reserved.
/////////////////////////////////////////////////////////////////////


// TCIterator.h : header file
//

#if !defined(_TCITERATOR_H__INCLUDED_)
#define _TCITERATOR_H__INCLUDED_

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

#ifndef __AFXTEMPL_H__
	#pragma message ("To avoid this warning message place #include <afxtempl.h> in your stdafx.h precompiler headers file")
	#include <afxtempl.h>
#endif

/////////////////////////////////////////////////////////////////////////////
// TTCIterator (Declaration)

template <class T>
class TTCIterator : public T
{
public:
// Construction
	TTCIterator();

// Operations
public:
	void Initialize(bool bDeepIteration= true);

	HTREEITEM GetNext();

// Implementation
private:
	bool m_bDeepIteration;

	CList<HTREEITEM, HTREEITEM> m_hlTail;
};


/////////////////////////////////////////////////////////////////////////////
// TTCIterator (Implementation)

template <class T>
TTCIterator<T>::TTCIterator()
{
	m_bDeepIteration= true;
}

template <class T>
void TTCIterator<T>::Initialize(bool bDeepIteration)
{
	m_bDeepIteration= bDeepIteration;

	m_hlTail.AddTail(GetRootItem());
}

template <class T>
HTREEITEM TTCIterator<T>::GetNext()
{
	HTREEITEM htiRet= NULL;

	if (m_hlTail.GetHeadPosition() != NULL)
	{
		htiRet= m_hlTail.GetHead();
		
		m_hlTail.RemoveHead();

		// Siblings
		if (GetNextSiblingItem(htiRet) != NULL)
			m_hlTail.AddHead(GetNextSiblingItem(htiRet));

		// Children
		if (ItemHasChildren(htiRet))
		{
			if (m_bDeepIteration)
				m_hlTail.AddHead(GetChildItem(htiRet));
			else
				m_hlTail.AddTail(GetChildItem(htiRet));
		}
	}

	return htiRet;
}

#endif // !defined(_TCITERATOR_H__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)

Share

About the Author

Francisco José Sen del Prado
Software Developer (Senior)
Spain Spain
I started programming in Basic language when I was 14 years old. The second programming language I learned was Z80 assembler. I've been programming with C++ for the last 20 years. I attended the 2012 C++ Now event in Aspen and it was the most exciting experience I've lived in my professional life. I met a lot of brilliant C++ minds and I have very good memories from that trip.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.1411022.1 | Last Updated 12 Jun 2001
Article Copyright 2001 by Francisco José Sen del Prado
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid