Click here to Skip to main content
Licence 
First Posted 22 Apr 2003
Views 49,123
Bookmarked 24 times

WTL CFileTreeCtrl class

By | 22 Apr 2003 | Article
Implements a tree control similar to the left hand side of Windows Explorer

Sample Image - wtlfiletreectrl.jpg

Credit and Acknowledgments

The original author of FileTree MFC control is PJ Naughter. This control and article can be found at http://www.codeproject.com/treectrl/filetree.asp

Overview

I needed a FileTree control to use in an ATL/WTL project and I decided to port MFC Control to WTL. The following ATL files contain the port:

  • FileFind.h/FileFind.cpp - Contain the CFileFind class and implementation for WTL which performs local file searches
  • WtlFileTreeCtrl.h/WtlFileTreeCtrl.cpp - Contain the CWtlFileTreeCtrl class and implementation for WTL

How to use the control in your WTL App:

  1. Create a WTL Project
  2. Design the dialog and add the Tree control
  3. Add the WtlFileTreeCtrl.h header file to your project
  4. Assign a CWtlFileTreeCtrl to your tree.
  5. In OnInitDialog(), subclass tree control (CWtlFileTreeCtrl) to ID using the SubclassWindow method.
  6. In your dialog, don't forget to add the macro REFLECT_NOTIFICATIONS which allows the CWtlFileTreeCtrl to get messages like TVN_ITEMEXPANDING.
#include "WtlFileTreeCtrl.h"

//...

class CMainDlg : public CDialogImpl<CMainDlg>
{
     BEGIN_MSG_MAP(CMainDlg)
          ...
          MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
          REFLECT_NOTIFICATIONS()
     END_MSG_MAP()
     ...
     LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, 
         LPARAM /*lParam*/, BOOL& /*bHandled*/);
     ...
     CWtlFileTreeCtrl m_Tree;
     ...
};

//...

LRESULT CMainDlg::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, 
        LPARAM /*lParam*/, BOOL& /*bHandled*/) 

{
     ...
     m_Tree.SubclassWindow( ::GetDlgItem( m_hWnd, IDC_TREE1 ) );
     ...
}

Requirements

You will require the WTL Libraries, these can be downloaded from the microsoft site.

Note - This control uses the STL std::string class and the STL std::vector template class.

Contacting the Author

Ilya Solnyshkin, E-mail: isolnyshkin@yahoo.com, Web: http://www.printsniffer.com/

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

About the Author

Ilya Solnyshkin

Web Developer

Canada Canada

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralBug: GDI object leak PinmemberLeon Oskam7:39 9 Aug '09  
Generalbug PinmemberDmitry AE23:04 15 Nov '07  
Hello, Dear Ilya.
I have some problems in this code :
 
std::string CFileFind::GetFilePath() const
{
if( m_hContext == NULL)
return FALSE;
 
std::string strResult = m_strRoot;
if (strResult[strResult.size()-1] != '\\' &&
strResult[strResult.size()-1] != '/')
strResult += m_chDirSeparator;
strResult += GetFileName();
return strResult;
}
 
If m_strRoot == "" - this code do something as strResult[-1] and spring up error.
Thanks.
GeneralRe: bug Pinmembertoddma9:56 21 Sep '11  
GeneralRe: bug Pinmembertoddma2:27 23 Sep '11  
GeneralTo make it compile [modified] Pinmemberjsanjosem23:57 5 Mar '07  
Generalerror of link Pinmemberkayssar@lycos.com23:48 3 Apr '05  
GeneralRe: error of link PinmemberIlya Solnyshkin6:04 4 Apr '05  
Generalbugfix Pinmemberevbersen0:58 16 Dec '03  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web01 | 2.5.120529.1 | Last Updated 23 Apr 2003
Article Copyright 2003 by Ilya Solnyshkin
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid