Click here to Skip to main content
15,867,568 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: Can edit box or combo box be added into the cell of list? Pin
freehawk14-May-04 18:21
freehawk14-May-04 18:21 
GeneralRe: Can edit box or combo box be added into the cell of list? Pin
petes9-Nov-04 22:25
professionalpetes9-Nov-04 22:25 
Generali'm rookie in MFC Pin
browar5-May-04 6:12
browar5-May-04 6:12 
GeneralRe: i'm rookie in MFC Pin
browar6-May-04 9:33
browar6-May-04 9:33 
GeneralProblem: Debug-Version faster than Release-Version Pin
Anonymous17-Mar-04 21:37
Anonymous17-Mar-04 21:37 
GeneralRe: Problem: Debug-Version faster than Release-Version Pin
Anonymous18-Mar-04 1:52
Anonymous18-Mar-04 1:52 
GeneralRe: Problem: Debug-Version faster than Release-Version Pin
Anonymous18-Mar-04 1:57
Anonymous18-Mar-04 1:57 
GeneralRe: Problem: Debug-Version faster than Release-Version Pin
TigerX22-Mar-04 16:46
professionalTigerX22-Mar-04 16:46 
GeneralRe: Problem: Debug-Version faster than Release-Version Pin
songsongsong29-Oct-04 20:21
songsongsong29-Oct-04 20:21 
GeneralRe: Problem: Debug-Version faster than Release-Version Pin
Anonymous11-Jan-05 16:38
Anonymous11-Jan-05 16:38 
GeneralRe: Problem: Debug-Version faster than Release-Version Pin
Anonymous11-Jan-05 16:47
Anonymous11-Jan-05 16:47 
GeneralRe: Problem: Debug-Version faster than Release-Version Pin
qiek11-Jan-05 16:53
qiek11-Jan-05 16:53 
GeneralRe: Problem: Debug-Version faster than Release-Version Pin
qiek11-Jan-05 17:26
qiek11-Jan-05 17:26 
Questiongreat, but how can I change Text ??? Pin
Gregor Schiller15-Mar-04 9:38
Gregor Schiller15-Mar-04 9:38 
AnswerRe: great, but how can I change Text ??? Pin
TigerX22-Mar-04 16:59
professionalTigerX22-Mar-04 16:59 
QuestionHow to display 256 colors image? Pin
Anonymous12-Mar-04 16:12
Anonymous12-Mar-04 16:12 
AnswerRe: How to display 256 colors image? Pin
TigerX22-Mar-04 17:06
professionalTigerX22-Mar-04 17:06 
GeneralWoo,Good control,Thank you very much!! Pin
pkapple11-Mar-04 15:09
pkapple11-Mar-04 15:09 
GeneralRe: Woo,Good control,Thank you very much!! Pin
TigerX22-Mar-04 17:09
professionalTigerX22-Mar-04 17:09 
GeneralScrollbars not displayed Pin
zqna5-Mar-04 8:47
zqna5-Mar-04 8:47 
GeneralRe: Scrollbars not displayed Pin
TigerX22-Mar-04 17:10
professionalTigerX22-Mar-04 17:10 
GeneralNew style for TreeList Pin
Anonymous30-Jan-04 5:21
Anonymous30-Jan-04 5:21 
GeneralRe: New style for TreeList Pin
TigerX16-Feb-04 23:53
professionalTigerX16-Feb-04 23:53 
GeneralTreeCtrl Not Move Pin
magnes16-Jan-04 4:17
magnes16-Jan-04 4:17 
GeneralEdit items Pin
Kess7-Jan-04 22:55
Kess7-Jan-04 22:55 

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.