Click here to Skip to main content
15,881,880 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

 
AnswerRe: 跪求,老大这个怎么编译Release版本? Pin
cnZhangcm26-Mar-09 22:21
cnZhangcm26-Mar-09 22:21 
GeneralRe: 跪求,老大这个怎么编译Release版本? Pin
spaceknight7-Jul-09 17:43
spaceknight7-Jul-09 17:43 
GeneralRe: 跪求,老大这个怎么编译Release版本? Pin
maicoye22-Jul-09 21:59
maicoye22-Jul-09 21:59 
QuestionCrashed when I Expand All the Items in Release Version Pin
mconstor27-Apr-08 19:36
mconstor27-Apr-08 19:36 
AnswerRe: Crashed when I Expand All the Items in Release Version Pin
mconstor31-May-08 18:26
mconstor31-May-08 18:26 
Generaltotally useles code for existing control Pin
kilt26-Apr-08 5:00
kilt26-Apr-08 5:00 
GeneralRe: totally useles code for existing control Pin
Kochise1-Oct-08 6:51
Kochise1-Oct-08 6:51 
Questionthe Combobox control cannot be dropdown when use together with TreeListCtrl in a same dialogbox [modified] Pin
doublestone8-Apr-08 2:51
doublestone8-Apr-08 2:51 
QuestionCan we use the code freely? Pin
Member 461932710-Dec-07 14:12
Member 461932710-Dec-07 14:12 
QuestionCan you not show expansion boxes on leaf items? PinPopular
hairy_hats14-Nov-07 23:45
hairy_hats14-Nov-07 23:45 
AnswerRe: Can you not show expansion boxes on leaf items? Pin
ahrdmy harmy8-Mar-09 20:52
ahrdmy harmy8-Mar-09 20:52 
QuestionHow to include TurboDLL staticaly into a project [modified] Pin
Kochise9-May-07 21:16
Kochise9-May-07 21:16 
AnswerRe: How to include TurboDLL staticaly into a project Pin
net_id1-Jan-09 19:58
net_id1-Jan-09 19:58 
Generalin-list editing of subitem Pin
Mike Eriksson12-Apr-07 23:49
Mike Eriksson12-Apr-07 23:49 
GeneralRe: in-list editing of subitem Pin
Mike Eriksson13-Apr-07 21:53
Mike Eriksson13-Apr-07 21:53 
GeneralRe: in-list editing of subitem Pin
Eimatsu6-Jul-08 16:11
Eimatsu6-Jul-08 16:11 
QuestionSorting? Pin
LittleIan3-Apr-07 1:02
LittleIan3-Apr-07 1:02 
QuestionSortChildren Pin
Jordan Walters2-Apr-07 12:24
Jordan Walters2-Apr-07 12:24 
GeneralCan't include in my .NET 2003 project!! Pin
Khanafer24-Nov-06 6:20
Khanafer24-Nov-06 6:20 
QuestionHow to implementation Print list item? Pin
JiaTang15-Oct-06 20:33
JiaTang15-Oct-06 20:33 
Generali can't add it in asp.net control(VB code) Pin
Phan Thanh Lam8-Oct-06 17:56
Phan Thanh Lam8-Oct-06 17:56 
GeneralRe: i can't add it in asp.net control(VB code) Pin
Christian Graus8-Oct-06 19:05
protectorChristian Graus8-Oct-06 19:05 
QuestionSet color in subitems Pin
catia_wapf3-Aug-06 2:20
catia_wapf3-Aug-06 2:20 
AnswerRe: Set color in subitems Pin
JiaTang15-Oct-06 20:29
JiaTang15-Oct-06 20:29 
GeneralCan´t delete columns... Pin
mightyCoCo17-Apr-06 1:44
mightyCoCo17-Apr-06 1:44 

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.