Click here to Skip to main content
15,884,388 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: Problems Linking Pin
TigerX24-Mar-03 15:54
professionalTigerX24-Mar-03 15:54 
GeneralRe: Problems Linking Pin
PoloM125-Mar-03 6:03
PoloM125-Mar-03 6:03 
GeneralThe Best TreeListCtrl I've ever seen Pin
mindows20-Mar-03 7:15
mindows20-Mar-03 7:15 
GeneralRe: The Best TreeListCtrl I've ever seen Pin
TigerX23-Mar-03 20:36
professionalTigerX23-Mar-03 20:36 
GeneralRe: The Best TreeListCtrl I've ever seen Pin
Paul Kissel18-Jun-03 12:44
Paul Kissel18-Jun-03 12:44 
GeneralRe: The Best TreeListCtrl I've ever seen Pin
_Manuel4-Sep-03 9:53
professional_Manuel4-Sep-03 9:53 
Generalsub item in tree Pin
Peleg M20-Jan-03 18:15
Peleg M20-Jan-03 18:15 
GeneralSubItem image Pin
Peleg M18-Jan-03 3:50
Peleg M18-Jan-03 3:50 
GeneralRe: SubItem image Pin
Anonymous20-Jan-03 17:42
Anonymous20-Jan-03 17:42 
GeneralRe: SubItem image Pin
rjahrman21-Sep-03 13:25
rjahrman21-Sep-03 13:25 
GeneralRe: SubItem image Pin
TigerX4-Oct-03 16:17
professionalTigerX4-Oct-03 16:17 
Generalreplace location Pin
Peleg M17-Jan-03 21:46
Peleg M17-Jan-03 21:46 
GeneralRe: replace location Pin
Anonymous20-Jan-03 17:51
Anonymous20-Jan-03 17:51 
GeneralRe: replace location Pin
Peleg M20-Jan-03 18:09
Peleg M20-Jan-03 18:09 
GeneralTroubles using with VC7 Pin
m@xx20-Nov-02 2:27
m@xx20-Nov-02 2:27 
GeneralRe: Troubles using with VC7 Pin
TigerX24-Nov-02 0:28
professionalTigerX24-Nov-02 0:28 
GeneralRe: Troubles using with VC7 Pin
m@xx25-Nov-02 0:17
m@xx25-Nov-02 0:17 
GeneralGreat control! Pin
m@xx18-Nov-02 20:43
m@xx18-Nov-02 20:43 
GeneralRe: Great control! Pin
TigerX19-Nov-02 3:49
professionalTigerX19-Nov-02 3:49 
QuestionSorting? Pin
Stefan Schwarzbach11-Nov-02 7:42
Stefan Schwarzbach11-Nov-02 7:42 
AnswerRe: Sorting? Pin
TigerX12-Nov-02 3:35
professionalTigerX12-Nov-02 3:35 
GeneralAbout OnRButtonDown Event Pin
Ende7-Nov-02 1:39
Ende7-Nov-02 1:39 
GeneralRe: About OnRButtonDown Event Pin
Anonymous8-Nov-02 5:13
Anonymous8-Nov-02 5:13 
GeneralRe: About OnRButtonDown Event Pin
TigerX9-Nov-02 13:16
professionalTigerX9-Nov-02 13:16 
GeneralCall from another Extension DLL. Pin
suresoo25-Sep-02 16:53
suresoo25-Sep-02 16:53 

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.