Click here to Skip to main content
15,886,518 members
Articles / Desktop Programming / MFC

A Tree List Control

Rate me:
Please Sign up or sign in to vote.
4.87/5 (83 votes)
19 Sep 2002 1.2M   23.7K   173   189
A Tree List Control

Introduction

This is a class derived from CWnd class. It's a tree control with a list.

Features

Below are some of the many features that CTreeListCtrl has:

  • Compatible with CTreeCtrl & CListCtrl
  • Header drag & drop
  • Drag & drop between CTreeListCtrl
  • Transparent drag window with Alpha blend
  • Double colors of list
  • Background image
  • Check box support
  • Lock box support
  • Embedded modified controls
  • No more in future

Snapshot 1

Image 1

Snapshot 2

Image 2

How to Use It

Add this string into stdafx.h:

C++
#include "..\\TurboDLL\\xTurboDll.h"

Define Your Controls

C++
class CMyTreeListCtrl : public CTreeListCtrl  
{
public:
  CMyTreeListCtrl();
  virtual ~CMyTreeListCtrl();

protected:
  //{{AFX_MSG(CMyTreeListCtrl)
  afx_msg void OnExpanding(NMHDR* pNMHDR, LRESULT* pResult);
  afx_msg void OnExpanded(NMHDR* pNMHDR, LRESULT* pResult);
  afx_msg void OnUpdating(NMHDR* pNMHDR, LRESULT* pResult);
  afx_msg void OnUpdated(NMHDR* pNMHDR, LRESULT* pResult);
  afx_msg void OnBeginDrag(NMHDR* pNMHDR, LRESULT* pResult);
  afx_msg void OnDragEnter(NMHDR* pNMHDR, LRESULT* pResult);
  afx_msg void OnDragLeave(NMHDR* pNMHDR, LRESULT* pResult);
  afx_msg void OnDragOver(NMHDR* pNMHDR, LRESULT* pResult);
  afx_msg void OnDrop(NMHDR* pNMHDR, LRESULT* pResult);
  //}}AFX_MSG

  DECLARE_MESSAGE_MAP()
};

Use Your Controls

C++
class CTurboDragDlg : public CDialog
{
// Construction
public:
  CTurboDragDlg(CWnd* pParent = NULL);   // standard constructor
        ...
  CImageList  m_ImageList;
  CMyTreeListCtrl  m_tree1;
  CMyTreeListCtrl m_tree2;
        ...
};

CTurboDragDlg::OnInitDialog() 
{
  CDialog::OnInitDialog();
  
  // TODO: Add extra initialization here
  m_ImageList.Create( IDB_BITMAP_TREE, 16, 4, 0xFF00FF );

  CRect rect;
  GetClientRect(&rect);
  rect.DeflateRect( 5, 5, 5, 5 );

  CRect left;
  left = rect;
  left.right = ( rect.left + rect.right ) / 2;

  CRect right;
  right = rect;
  right.left = ( rect.left + rect.right ) / 2;

  m_tree1.Create( 0x50810000, left, this, 0 );
  m_tree2.Create( 0x50810000, right, this, 1 );

        // Add other initialize code here
        ...
        
        return TRUE;  // return TRUE unless you set the focus to a control
  // EXCEPTION: OCX Property Pages should return FALSE
}

Then use it freely.

License

This article has no explicit license attached to it, but may contain usage terms in the article text or the download files themselves. If in doubt, please contact the author via the discussion board below.

A list of licenses authors might use can be found here.


Written By
Chief Technology Officer
China China
He is a Visual C++ developer, MCSE
He has been programming in C/C++ for 7 years, Visual C++ with MFC for 5 years and RDBMS: Oracle, MS SQL for 5 years

Comments and Discussions

 
GeneralHeader resizing Pin
mmueller14-Dec-03 23:28
mmueller14-Dec-03 23:28 
GeneralRe: Header resizing Pin
Member 896145631-Dec-03 5:01
Member 896145631-Dec-03 5:01 
GeneralRe: Header resizing Pin
jcomer20-Feb-04 5:23
jcomer20-Feb-04 5:23 
GeneralRe: Header resizing Pin
IsgratteLapoche5-May-04 4:49
IsgratteLapoche5-May-04 4:49 
GeneralRe: Header resizing Pin
Shadim3-Jun-04 1:54
Shadim3-Jun-04 1:54 
GeneralEdit Item Pin
Hobosoft14-Dec-03 18:07
Hobosoft14-Dec-03 18:07 
GeneralRe: Edit Item Pin
MorrisYang6-Jan-04 13:39
MorrisYang6-Jan-04 13:39 
GeneralRe: Edit Item Pin
fanoble21-Apr-04 22:31
fanoble21-Apr-04 22:31 
GeneralWhy "Must Using MFC in Shared Dll Pin
Lowi12-Dec-03 2:23
Lowi12-Dec-03 2:23 
GeneralColumn Resizing Pin
progman_64-Nov-03 8:27
sussprogman_64-Nov-03 8:27 
GeneralRe: Column Resizing Pin
TigerX13-Nov-03 3:42
professionalTigerX13-Nov-03 3:42 
GeneralCombo box Pin
vetterh128-Oct-03 13:20
vetterh128-Oct-03 13:20 
GeneralA problem about the scroll bar. Pin
heavensdoor196023-Oct-03 20:58
heavensdoor196023-Oct-03 20:58 
GeneralSorting (TLI_SORT / TLF_SORT_ASC) Pin
schlotter25-Sep-03 3:50
schlotter25-Sep-03 3:50 
GeneralRe: Sorting (TLI_SORT / TLF_SORT_ASC) Pin
TigerX4-Oct-03 16:03
professionalTigerX4-Oct-03 16:03 
GeneralRe: Sorting (TLI_SORT / TLF_SORT_ASC) Pin
marccaron18-Nov-04 6:24
marccaron18-Nov-04 6:24 
GeneralCode for multiple selection with Shift key Pin
vetterh119-Aug-03 5:42
vetterh119-Aug-03 5:42 
GeneralRe: Code for multiple selection with Shift key Pin
TigerX7-Sep-03 16:53
professionalTigerX7-Sep-03 16:53 
GeneralCustom drawn button in tree control Pin
CSaikat22-Jun-03 22:35
CSaikat22-Jun-03 22:35 
GeneralRe: Custom drawn button in tree control Pin
TigerX7-Sep-03 17:18
professionalTigerX7-Sep-03 17:18 
GeneralTree Item Buttons Pin
shvez10-Jun-03 4:56
shvez10-Jun-03 4:56 
GeneralRe: Tree Item Buttons Pin
TigerX7-Sep-03 17:16
professionalTigerX7-Sep-03 17:16 
GeneralMemory Leak Pin
Josema12-May-03 0:02
Josema12-May-03 0:02 
GeneralRe: Memory Leak Pin
TigerX7-Sep-03 17:11
professionalTigerX7-Sep-03 17:11 
GeneralProblems Linking Pin
PoloM124-Mar-03 6:38
PoloM124-Mar-03 6:38 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.