Click here to Skip to main content
15,886,830 members
Articles / Desktop Programming / MFC

"Browse For Folder" dialog alike with source

Rate me:
Please Sign up or sign in to vote.
4.60/5 (5 votes)
5 Sep 2001 114.8K   1.7K   38  
Shell interfaces in use. IShellFolder, IEnumIDList, etc.
// ShellTreeNode.h: interface for the CShellTreeNode class.
//
// Written by Marat Bedretdinov (maratb@hotmail.com)
// Copyright (c) 2000.
//
// This code may be used in compiled form in any way you desire. This
// file may be redistributed unmodified by any means PROVIDING it is 
// not sold for profit without the authors written consent, and 
// providing that this notice and the authors name is included. 
//
// This file is provided "as is" with no expressed or implied warranty.
// The author accepts no liability if it causes any damage whatsoever.
// It's free - so you get what you pay for.

#if !defined(AFX_SHELLTREENODE_H__EB382053_1B3A_453D_9057_3B16452219FA__INCLUDED_)
#define AFX_SHELLTREENODE_H__EB382053_1B3A_453D_9057_3B16452219FA__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "TreeNode.h"

class CShellTreeNode;

class CShellHelper
{
friend class CShellTreeNode;
public:
					~CShellHelper();

		   void*	 Alloc(unsigned int);
		   void		 Free(void*);

// returns pidl for a special folder, the caller is responsible 
// for its deallocation via calling Free()

   LPITEMIDLIST      CreateSpecialPidl(int);

		  UINT       GetIDLSize(LPCITEMIDLIST pIDL) const;
  LPITEMIDLIST       GetIDL(LPITEMIDLIST pIDL, UINT) const;
  LPITEMIDLIST		 CopyPIdl(LPCITEMIDLIST);

           bool		 IsNetPath(LPCITEMIDLIST) const;
           bool		 IsNetPath(const char*) const;
private:
		             CShellHelper();

  IShellFolder*		 CreateDesktop() const;
//  IShellFolder*		 CreateMyComputer() const;

		  void       Init();
          void       Cleanup();

		   bool      AttachSystemImageList();
 
private:
  LPMALLOC		      m_pMalloc;
  CImageList          m_imgSysList;
// I'll use this to figure out if a fully qualified pidl belongs to Network
  LPITEMIDLIST		  m_pidlNetwork;
};

class CShellTreeNode : public ITreeNode  
{
public:
	                        CShellTreeNode();
	virtual                 ~CShellTreeNode();

  static   CShellHelper&	GetShellHelper() { return m_shell; }

                    void    Accept(CTreeVisitor&);

					void	Cleanup();

					void	FindChildren();

		      ITreeNode*	FindChild(const char*, UINT nSkip = 1);

		      ITreeNode*	FindChild(LPCITEMIDLIST);

			  ITreeNode*	FindImmediateChild(const char*, UINT);

			  ITreeNode*	FindImmediateChild(LPITEMIDLIST*);

			        void    SetFilter(UINT nFlags)
								{ m_nFlags = nFlags; }

	                UINT    GetFilter() const
								{ return m_nFlags; }

                    void	SetFindDepth(unsigned long n)
								{ m_nFindDepth = n; }

					bool	IsSearched() const
								{ return m_nFindDepth > 0; }

			  const char*	GetName();

			  const char*	GetNameDebug();
		
			  const char*	GetPath() const;

		   unsigned long	GetChildrenN() const
								{ return m_vecFiles.size(); }

	           ITreeNode*	GetChild(unsigned long n)
								{ if (m_vecFiles.size() > 0 && n > m_vecFiles.size()-1)
								    return 0; 
								  return m_vecFiles[n]; }

               ITreeNode*   GetParent() 
								{ return m_pParent; }

           IShellFolder*    GetShellFolder() {return m_pShellFolder;}

					bool	IsDirectory() const;

                    bool    IsSystemDirectory() const;

					bool    IsNetworkRoot();

					bool    IsNetworkNode();

					bool	HasChildren() const;

					bool	PeekChildren();

                     int    operator==(const ITreeNode&);

					bool	CompareFullUniqueID(void*);

					bool	CompareRelativeUniqueID(void*);

                    void*   GetRelativeUniqueId() const
								{ return m_pID; }

					void*   GetFullUniqueId() const
								{ return m_pFullID; }

        const SHFILEINFO&   GetSmallIcon();

        const SHFILEINFO&   GetSmallOpenIcon();

	static    CImageList*   GetSystemSmallImageList() 
//								{ return &m_shell.m_imgList;}
								{ return &m_shell.m_imgSysList;}

                    void    RunIt();
			        void    StrRetToString(STRRET, LPITEMIDLIST, string&);
protected:
	                        CShellTreeNode(CShellTreeNode*, LPITEMIDLIST pID, UINT nFlags, unsigned long nThisDepth, unsigned long nFindDepth);

					void    CreateFullPIDL();

				 string&    GetNameRef();
			     string&    GetPathRef();

					void    SetIShellFolder(IShellFolder*);

                    void    RetrieveSmallIcon();

                    void    RetrieveSmallOpenIcon();

protected:
	CShellTreeNode*			m_pParent;
	vector<CShellTreeNode*>	m_vecFiles;
	IShellFolder*           m_pShellFolder;
	IShellIcon*             m_pShellIcon;
	LPITEMIDLIST   	        m_pID;
	LPITEMIDLIST   	        m_pFullID;
    static CShellHelper     m_shell;
	UINT					m_nFlags;
	string                  m_strLastError;
	string					m_strName;
	string					m_strPath;
	string                  m_strDebug;
	unsigned long			m_nThisDepth;
	unsigned long			m_nFindDepth;
	char					m_szIconFile[MAX_PATH];
    SHFILEINFO				m_ifSmall;
	SHFILEINFO				m_ifSmallOpen;
};

#endif // !defined(AFX_SHELLTREENODE_H__EB382053_1B3A_453D_9057_3B16452219FA__INCLUDED_)

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

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



Comments and Discussions