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

 
GeneralRe: Unable to Respond to a OnSelchanged message Pin
yokosuna1-Dec-05 2:44
yokosuna1-Dec-05 2:44 
GeneralUnable to add TreeListCtrl in PropetyPage Pin
15-Dec-04 2:15
suss15-Dec-04 2:15 
Generaldelete tree Pin
jerry li9-Dec-04 22:47
jerry li9-Dec-04 22:47 
Generalcontrol gets locked Pin
Member 15409728-Oct-04 0:08
Member 15409728-Oct-04 0:08 
GeneralRe: control gets locked Pin
marccaron18-Nov-04 3:50
marccaron18-Nov-04 3:50 
GeneralRe: control gets locked Pin
rpar21-Oct-05 3:48
rpar21-Oct-05 3:48 
GeneralBug when using in release version Pin
pir21-Oct-04 1:57
pir21-Oct-04 1:57 
QuestionHow tu do use it in MFC dll? Pin
TangQin12-Oct-04 5:08
TangQin12-Oct-04 5:08 
AnswerRe: How tu do use it in MFC dll? Pin
marccaron20-Sep-05 11:23
marccaron20-Sep-05 11:23 
GeneralWhy must use MFC in Shared DLL Pin
liuliu7-Sep-04 17:57
liuliu7-Sep-04 17:57 
QuestionHow to add button control in one of the columns Pin
cool_jay26-Aug-04 0:00
cool_jay26-Aug-04 0:00 
GeneralImplementation for "ExpandAll" Pin
nocknock11-Aug-04 21:57
nocknock11-Aug-04 21:57 
GeneralRe: Implementation for "ExpandAll" Pin
Norrie Taylor22-Feb-05 7:58
Norrie Taylor22-Feb-05 7:58 
GeneralRe: Implementation for "ExpandAll" Pin
Steve Kowald29-Jun-05 8:57
Steve Kowald29-Jun-05 8:57 
QuestionHow can I change color of the specified treelist item Pin
nocknock11-Aug-04 20:48
nocknock11-Aug-04 20:48 
Questiontransparent tree control ? Pin
Seshagiri4-Aug-04 0:23
Seshagiri4-Aug-04 0:23 
GeneralDDL to LIB Pin
Member 9414921-Jun-04 20:44
Member 9414921-Jun-04 20:44 
GeneralRe: DDL to LIB Pin
Rilhas10-Jul-04 9:25
Rilhas10-Jul-04 9:25 
QuestionHow to get the first visible item of screen? Pin
freehawk11-May-04 22:49
freehawk11-May-04 22:49 
AnswerRe: How to get the first visible item of screen? Pin
vrumfundel16-May-04 10:29
vrumfundel16-May-04 10:29 
QuestionHow to set the font color of cell in the list? Pin
freehawk11-May-04 21:42
freehawk11-May-04 21:42 
AnswerRe: How to set the font color of cell in the list? Pin
itaifrenkel31-May-04 4:39
itaifrenkel31-May-04 4:39 
QuestionCan edit box or combo box be added into the cell of list? Pin
freehawk9-May-04 19:36
freehawk9-May-04 19:36 
AnswerRe: Can edit box or combo box be added into the cell of list? Pin
vrumfundel11-May-04 9:52
vrumfundel11-May-04 9:52 
GeneralRe: Can edit box or combo box be added into the cell of list? Pin
freehawk11-May-04 15:06
freehawk11-May-04 15:06 

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.