Click here to Skip to main content
12,506,733 members (63,052 online)
Click here to Skip to main content
Add your own
alternative version

Stats

742.7K views
10.6K downloads
124 bookmarked
Posted

CShellTreeCtrl

, 18 Dec 2001
Rate this:
Please Sign up or sign in to vote.
A CWaitingTreeCtrl-derived class to display Shell's resources

CShellTreeCtrl

This is just an example of a content provider class (see article), which overrides the PopulateItem virtual function to show the Shell's resources only when the user wants to access them.

You may easily specify the resource to use as the tree control's root item, or add multiple items at the root level. You have options to display only folders, files, hidden objects, and you can choose how to display the items text. You may also get specific information about the resource associated with an existing item.

User interface features are those offered by the base class and can be further personalized with custom animations.

This version is still under development, in particular there's no support for filtering (I accept ideas).

Demo Application

The demo project shows how to:

  • use the control in a SDI application
  • add root items to the control
  • set item's options
  • display a Shell context menu

You may use the "Test" menu to experiment with the selected item, or see the Shell context menu in the "Shell" menu. Another way to display the Shell context menu is by right-clicking on a tree item (hold on CTRL to see a cascaded popup menu).

Class Reference

CShellTreeCtrl (still subject to change)

CShellTreeCtrl::AddRootItem

void AddRootItem(LPCITEMIDLIST pidl, UINT nFlags = STCF_DEFAULT)
Adds the specified Shell object to the root level of the tree and sets options for the inserted item.

The first argument pidl is the the object you want to add, cannot be NULL. You may use SHGetSpecialFolderLocation to get a valid argument for this function.

The nFlags argument specifies the options to apply to the inserted item and can be one or more of the following values, combined with the bitwise or operator:

STCF_DEFAULT Child items can be only folders and their names refers to the parent item (like Explorer)
STCF_INCLUDEFILES Child items can be also non-folder objects
STCF_INCLUDEHIDDEN Child items can be also hidden objects (like system files)
STCF_INCLUDEALL (STCF_INCLUDEFILES|STCF_INCLUDEHIDDEN)
STCF_SHOWFULLNAME Item's name does not refer to any other folder (like shared directories in the Network Neighboorhood folder)
STCF_SHOWPATH Item's name is a relative path
STCF_SHOWFULLPATH Item's name is an absolute path

(STCF_SHOWPATH|STCF_SHOWFULLNAME)

CShellTreeCtrl::AddRootFolderContent

void AddRootFolderContent(LPCITEMIDLIST pidl, UINT nFlags = STCF_DEFAULT)
Adds the content of the specified Shell folder object to the root level of the tree and sets options for the inserted items.

The first argument pidl is the the folder object you want to enumerate. A value of NULL means that the Desktop virtual folder will be added (not its content). You may use SHGetSpecialFolderLocation to get a valid argument for this function.

The nFlags argument specifies the options to apply to the folder object during enumeration (see the previous function). STCF_SHOWxxx flags currently have no effect.

CShellTreeCtrl::GetItemIDList

CShellPidl GetItemIDList(HTREEITEM hItem)
It retrieves the Shell object associated to the specified item. The returned object is invalid if the function fails.

You may use the Shell's functions to get info about the returned value. See SHGetPathFromIDList, SHGetFileInfo documentation.

CShellTreeCtrl::GetItemContextMenu

BOOL GetItemContextMenu(HTREEITEM hItem, CShellContextMenu &rCtxMenu)
It retrieves the Shell context menu associated to the specified item. The return value is non-zero if the function is successful.

(to do)

CShellTreeCtrl::GetCallbackMask

UINT GetCallbackMask()
It retrieves which parts of a tree view item are handled by callback messages.

(see the next function)

CShellTreeCtrl::SetCallbackMask

void SetCallbackMask(UINT nMask)
It specifies which parts of a tree view item are handled by callback messages.

The nMask argument can be one or more of the following values, combined with the bitwise or operator:

TVIF_TEXT The control provides item text each time it's needed
TVIF_IMAGE same for the image
TVIF_SELECTEDIMAGE same for the selected image
TVIF_CHILDREN same for the item's button

 

Updates

17 Oct 2000

Initial public release.

7 Feb 2000

Fixed a bug with SHGetFileInfo on some machines, now using IShellFolder::GetAttributesOf (thanks to He Yingxia and Markus Axelsson)
Now correctly sort items after insertion

23 Nov 2001

New version of the control (beta)
Added wrapper classes for shell objects and interfaces
Added support for context menu

Conclusion

Please note that this class is not fully functional yet. Any suggestion on how to improve it would be greatly appreciated.

I developed this class also to provide an example of a content provider for my CWaitingTreeCtrl class (see article).

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

Share

About the Author

Paolo Messina
Technical Lead RoboTech srl
Italy Italy
Paolo began programming at the age of 9 with a glorious Olivetti M24 (i8086) and GW-BASIC, then he played a bit with Turbo C, Turbo Pascal and Assembly (using the MS-DOS Debug). Quick BASIC and Visual Basic shortly followed, until he learned C++ in College. He tought himself MFC and Windows programming, along with some DHTML and Javascript.

Always attracted by low-level programming and Assembly, he started to appreciate the joys of templates and STL while working for his Master Thesis. For seven months he was playing with airplanes and automatic control at the Unversity of Illinois at Urbana-Champaign, where he first met QNX and embedded systems.

In his job experience he learned Java to develop user interfaces and graphical editors, and re-discovered the Eclipse IDE that he had used in its early versions with the QNX SDK. He also deepened his knowledge of Linux and embedded systems, microcontrollers firmware and embedded voice recognition, while also practicing electronics design.

He graduated in Computer Engineering (Ingegneria informatica) at the University of Pisa, Italy, in December 2003. Currently working for an edutainment robotics company (www.robotechsrl.com).

He lives in Peccioli (Pisa) and Follonica (GR), Italy.

You may also be interested in...

Pro
Pro

Comments and Discussions

 
QuestionHow to reliably jump to a network path? Pin
jimwillsher12-Feb-07 22:06
memberjimwillsher12-Feb-07 22:06 
GeneralProblem with adding checkboxes Pin
iohanson21-Jan-07 23:11
memberiohanson21-Jan-07 23:11 
QuestionCompile for Unicode? Pin
vg8open19-Dec-06 12:31
membervg8open19-Dec-06 12:31 
AnswerRe: Compile for Unicode? Pin
ppaappuuss16-Jan-07 6:29
memberppaappuuss16-Jan-07 6:29 
GeneralRe: Compile for Unicode? Pin
vg8open20-Jan-07 13:13
membervg8open20-Jan-07 13:13 
QuestionHow to ask the tree control to select a item if I only konw the path of the item? Pin
Aki Wang17-Sep-06 21:20
memberAki Wang17-Sep-06 21:20 
AnswerRe: How to ask the tree control to select a item if I only konw the path of the item? Pin
Paolo Messina18-Sep-06 1:32
memberPaolo Messina18-Sep-06 1:32 
GeneralRe: How to ask the tree control to select a item if I only konw the path of the item? Pin
Aki Wang20-Sep-06 18:36
memberAki Wang20-Sep-06 18:36 
QuestionHow to show the Desktop ico as root? Pin
Aki Wang8-Aug-06 21:02
memberAki Wang8-Aug-06 21:02 
AnswerRe: How to show the Desktop ico as root? Pin
Paolo Messina10-Aug-06 7:55
memberPaolo Messina10-Aug-06 7:55 
GeneralRe: How to show the Desktop ico as root? Pin
Aki Wang10-Aug-06 16:26
memberAki Wang10-Aug-06 16:26 
General"Shell Controls Lib" cannot be downloaded. Pin
takayuki san19-Jul-06 13:07
membertakayuki san19-Jul-06 13:07 
GeneralRe: "Shell Controls Lib" cannot be downloaded. Pin
Paolo Messina18-Sep-06 1:20
memberPaolo Messina18-Sep-06 1:20 
QuestionUnicode Version Pin
MorpheusX5-Apr-06 10:48
memberMorpheusX5-Apr-06 10:48 
AnswerRe: Unicode Version Pin
Paolo Messina6-Apr-06 22:34
memberPaolo Messina6-Apr-06 22:34 
GeneralHi,Dear Paolo Messina , I'd like you to help me this if you are not busy :) Pin
JimOcean16-Feb-06 6:16
memberJimOcean16-Feb-06 6:16 
GeneralWhat's different between your PIDL::GetLength with IMalloc::getsize Pin
JimOcean16-Feb-06 4:48
memberJimOcean16-Feb-06 4:48 
GeneralRe: What's different between your PIDL::GetLength with IMalloc::getsize Pin
Paolo Messina16-Feb-06 5:04
memberPaolo Messina16-Feb-06 5:04 
GeneralRe: What's different between your PIDL::GetLength with IMalloc::getsize Pin
JimOcean16-Feb-06 5:13
memberJimOcean16-Feb-06 5:13 
GeneralRe: What's different between your PIDL::GetLength with IMalloc::getsize Pin
JimOcean16-Feb-06 5:25
memberJimOcean16-Feb-06 5:25 
GeneralRe: What's different between your PIDL::GetLength with IMalloc::getsize Pin
Paolo Messina17-Feb-06 3:01
memberPaolo Messina17-Feb-06 3:01 
GeneralI am trying to add Serialize into your great class CShellPidl,I do as follow, Pin
JimOcean18-Feb-06 21:44
memberJimOcean18-Feb-06 21:44 
GeneralRe: I am trying to add Serialize into your great class CShellPidl,I do as follow, Pin
Paolo Messina19-Feb-06 23:02
memberPaolo Messina19-Feb-06 23:02 
GeneralRe: I am trying to add Serialize into your great class CShellPidl,I do as follow, Pin
JimOcean20-Feb-06 3:51
memberJimOcean20-Feb-06 3:51 
GeneralOld project fails to compile too Pin
Steve_230934n513k5n132oi512307-Feb-06 8:59
memberSteve_230934n513k5n132oi512307-Feb-06 8:59 
AnswerRe: Old project fails to compile too - Latest code at SourceForge Pin
Paolo Messina7-Feb-06 22:16
memberPaolo Messina7-Feb-06 22:16 
GeneralRe: Old project fails to compile too - Latest code at SourceForge Pin
Michael Chapman13-Jun-06 7:54
memberMichael Chapman13-Jun-06 7:54 
AnswerLatest code at SourceForge - Bugs and VS.Net 2005 Pin
Mr. S30-Oct-06 3:41
memberMr. S30-Oct-06 3:41 
GeneralRe: Old project fails to compile too Pin
MagsJauregui14-Jun-10 9:26
memberMagsJauregui14-Jun-10 9:26 
General*Sigh* Another compiler error Pin
Steve_230934n513k5n132oi512307-Feb-06 8:54
memberSteve_230934n513k5n132oi512307-Feb-06 8:54 
QuestionRe: *Sigh* Another compiler error Pin
Neville Franks7-Feb-06 9:14
memberNeville Franks7-Feb-06 9:14 
AnswerRe: *Sigh* Another compiler error Pin
Steve_230934n513k5n132oi512307-Feb-06 9:24
memberSteve_230934n513k5n132oi512307-Feb-06 9:24 
GeneralRe: *Sigh* Another compiler error Pin
Neville Franks7-Feb-06 9:30
memberNeville Franks7-Feb-06 9:30 
GeneralRe: *Sigh* Another compiler error Pin
Michael Chapman12-Jun-06 14:12
memberMichael Chapman12-Jun-06 14:12 
GeneralRe: *Sigh* Another compiler error Pin
TruthSeeker16908-May-08 7:08
memberTruthSeeker16908-May-08 7:08 
GeneralCompiler error in ShellTreeCtrl.cpp Pin
Steve_230934n513k5n132oi512307-Feb-06 8:50
memberSteve_230934n513k5n132oi512307-Feb-06 8:50 
QuestionWould you like to tell me How can i Serialize your Class CShellpidl into a file? Pin
JimOcean2-Feb-06 5:37
memberJimOcean2-Feb-06 5:37 
AnswerRe: Would you like to tell me How can i Serialize your Class CShellpidl into a file? Pin
Paolo Messina7-Feb-06 22:22
memberPaolo Messina7-Feb-06 22:22 
QuestionExcellent! But can't display icon in non-dialog window? Pin
chenkaijiang@yahoo.com18-Jan-06 23:32
memberchenkaijiang@yahoo.com18-Jan-06 23:32 
AnswerRe: Excellent! But can't display icon in non-dialog window? Pin
Paolo Messina7-Feb-06 22:27
memberPaolo Messina7-Feb-06 22:27 
GeneralRe: Excellent! But can't display icon in non-dialog window? Pin
chenkaijiang@yahoo.com9-Feb-06 16:19
memberchenkaijiang@yahoo.com9-Feb-06 16:19 
AnswerRe: Excellent! But can't display icon in non-dialog window? Pin
Paolo Messina18-Feb-06 6:11
memberPaolo Messina18-Feb-06 6:11 
QuestionPls help me,How can i add IID_IShellDetails to function EnumFolderItems? Pin
JimOcean15-Jan-06 5:00
memberJimOcean15-Jan-06 5:00 
AnswerWould anybody help me? Pin
JimOcean18-Jan-06 7:52
memberJimOcean18-Jan-06 7:52 
Generalsugestion Pin
Max Santos14-Jan-06 15:17
memberMax Santos14-Jan-06 15:17 
Questionwhere does your shelltree free the pData ? Pin
JimOcean11-Jan-06 16:44
memberJimOcean11-Jan-06 16:44 
AnswerRe: where does your shelltree free the pData ? Pin
Paolo Messina11-Jan-06 22:45
memberPaolo Messina11-Jan-06 22:45 
GeneralRe: where does your shelltree free the pData ? Pin
TomboBE31-Jan-06 12:10
memberTomboBE31-Jan-06 12:10 
Generalif is there a bug when i use SHGetDataFromIDList Pin
JimOcean3-Jan-06 5:57
memberJimOcean3-Jan-06 5:57 
AnswerRe: if is there a bug when i use SHGetDataFromIDList Pin
Paolo Messina3-Jan-06 23:35
memberPaolo Messina3-Jan-06 23:35 

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.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160927.1 | Last Updated 19 Dec 2001
Article Copyright 2000 by Paolo Messina
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid