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

 
QuestionHow to print? Pin
JiaTang27-Mar-06 19:05
JiaTang27-Mar-06 19:05 
GeneralLot of Flicker when Resizing Pin
Dhananjay Gune8-Mar-06 11:58
professionalDhananjay Gune8-Mar-06 11:58 
QuestionFind a bug when moving colums PinPopular
ochoteau7-Dec-05 23:59
ochoteau7-Dec-05 23:59 
AnswerRe: Find a bug when moving colums Pin
hoker.ffb28-Jun-06 20:57
hoker.ffb28-Jun-06 20:57 
General@TigerX Pin
yokosuna30-Nov-05 19:08
yokosuna30-Nov-05 19:08 
GeneralDone it, done that... Pin
Kochise20-Jan-06 4:56
Kochise20-Jan-06 4:56 
GeneralThanks alot ... Pin
yokosuna27-Jun-06 0:19
yokosuna27-Jun-06 0:19 
GeneralWell, hrem... Pin
Kochise4-Jul-06 22:13
Kochise4-Jul-06 22:13 
GeneralSolved ! Pin
yokosuna5-Sep-06 4:09
yokosuna5-Sep-06 4:09 
GeneralRe: Done it, done that... Pin
hairy_hats20-Nov-07 3:39
hairy_hats20-Nov-07 3:39 
GeneralRe: Done it, done that... Pin
CODE-VCPP19-Feb-09 5:24
CODE-VCPP19-Feb-09 5:24 
GeneralRe: Done it, done that... Pin
Hans Dietrich3-Nov-10 4:24
mentorHans Dietrich3-Nov-10 4:24 
GeneralPosted on my Github Pin
Kochise19-Dec-16 8:34
Kochise19-Dec-16 8:34 
GeneralRe: Done it, done that... Pin
skyformat99@gmail.com12-Aug-12 20:01
skyformat99@gmail.com12-Aug-12 20:01 
GeneralBug in void CTreeListCtrl::ExchangeItem( CTreeListItem* pItemA, CTreeListItem* pItemB ) Pin
TomFromCZE12-Nov-05 15:00
TomFromCZE12-Nov-05 15:00 
GeneralRe: Bug in void CTreeListCtrl::ExchangeItem( CTreeListItem* pItemA, CTreeListItem* pItemB ) Pin
rrrado6-Nov-07 3:22
rrrado6-Nov-07 3:22 
GeneralTrying to use it in a non-dialog-based application. Pin
alexR7522-Oct-05 10:59
alexR7522-Oct-05 10:59 
GeneralRe: Trying to use it in a non-dialog-based application. Pin
ochoteau8-Dec-05 2:41
ochoteau8-Dec-05 2:41 
GeneralAdded move enhancements Pin
Peter Shafton31-Aug-05 8:29
Peter Shafton31-Aug-05 8:29 
QuestionHow can I get this control as .NET assembly or ActiveX control? Pin
Member 192519730-Apr-05 2:20
Member 192519730-Apr-05 2:20 
AnswerRe: How can I get this control as .NET assembly or ActiveX control? Pin
Kochise13-Jul-05 1:58
Kochise13-Jul-05 1:58 
GeneralGreat Job Pin
mr. Vitaliy A. Genkin6-Apr-05 18:05
mr. Vitaliy A. Genkin6-Apr-05 18:05 
Generalwhy can't get POS:( Pin
No-Cloud-Dagon1-Apr-05 14:36
No-Cloud-Dagon1-Apr-05 14:36 
GeneralUsing my own dialog to edit cells Pin
net_id26-Mar-05 16:35
net_id26-Mar-05 16:35 
GeneralUnable to Respond to a OnSelchanged message Pin
Rolando Cruz31-Jan-05 2:26
Rolando Cruz31-Jan-05 2:26 

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.