Path Picker with Network Capabilities

Environment: VC6 SP2
This DLL displays a directory tree similar to the one found in "Find in Files" Browse button. See below.
I have noticed several applications requiring a user to select a path that often use CFileDialog which does not fit the task very well. A better option is to use a Tree control but I have not found any that allow access to the network other than via mapped drives. Both methods lack the style that "Find in Files" provides.
I have developed the Dialog as a DLL for easy implementation. The source is written to put the Dialog object into a single class so it can be hacked out and used in any willing developers code.
How to use it.
I have provided two ways of using this code. Using the DLL directly requires the least effort, but allows least customisation.Method 1 - Adding to your own project.
- Copy the source files DlgGetPath.cpp and DlgGetPath.h to your Project directory and add them to your project.
- Change #include "PathPicker.h" to the name of your project as necessary.
- From within your project open the PathPicker.rc file and drag the Bitmap and Dialog into your project.
- Add the following code where you want to activate the Picker dialog. ie in a button handler.
#include "DlgGetPath.h" //Definition to get path ... void CBlarOnButtonBrowse() { CDlgGetPath dlgPath( this ); dlgPath.SetTitle( _T("Blar..") ); dlgPath.m_sTopNote = _T("Blar blar blar..."); if( dlgPath.DoModal() == IDOK ) { //Do some cool stuff with it here //SetDlgItemText( IDC_EDIT_SEARCH_IN, dlgPath.GetPath() ); } }
- Link your project with PathPicker.lib and insert the following code where you want the dialog to appear.
- Place the PathPicker.DLL in the same directory as your app or the System directory.
#include "PathPickerDll.h" ... //Once the parent window is created TCHAR szPath[200]; ShowDialog( (long)m_hWnd, "Blar.", "Blar blar...", szPath, 199 ); MessageBox( szPath );
Notes.
- This code was developed using VC++ 6.0, SP 2.0.
- Notes on limitations are in Source file DlgGetPath.cpp.
Downloads
Download DLL files and Method2 sample - 12 Kb

Comments
Great stuff!!! Added a selection routine to select a given path
Posted by bgsommerfeld on 03/27/2006 05:06pmI saw a need to add a selection routine to select a given path. This is helpful when the user keeps going back to the same folder. Here's the code. bool CDlgGetPath::SelectItem(HTREEITEM hItem, CString szFindPath, CString szFullPath) { bool bContinue = true; CString szCurPath; CString szCompare; if( szFindPath.IsEmpty() ) return false; if( szFindPath[szFindPath.GetLength()-1] != '\\' ) szFindPath += "\\"; szFindPath.MakeLower(); szCompare = szFindPath.SpanExcluding( "\\" ); szFindPath = szFindPath.Mid( szCompare.GetLength() + 1 ); szFullPath += szCompare; szFullPath += "\\"; if( szCompare.IsEmpty() || !hItem ) { // We couldn't find it...abort return false; } // //Search through the siblings for the current segment // while( bContinue && hItem ) { szCurPath = m_Tree.GetItemText( hItem ); szCurPath.MakeLower(); if( szCurPath == szCompare ) { // We found this segment m_Tree.SelectItem( hItem ); PopulateTree( szFullPath, hItem ); if( szCompare.GetLength() < 1 ) { // We found it...stop bContinue = false; } else { // Now traverse through our children HTREEITEM hChildItem = m_Tree.GetChildItem( hItem ); bContinue = SelectItem( hChildItem, szFindPath, szFullPath ); } } hItem = m_Tree.GetNextSiblingItem( hItem ); } return bContinue; }ReplyHelp : Tree Item link to directory
Posted by Legacy on 02/09/2004 12:00amOriginally posted by: zeus
Is there a possible way to link a directory directly
to a tree Item instead of starting from the C: directory???
Any help will be appreciated(sample code,etc..)
Thanks...
ReplyDisplaying files within directory???
Posted by Legacy on 12/04/2001 12:00amOriginally posted by: Maitri Venkat-Ramani
How do you modify the code to display files in each directory???
Thank you!!
ReplyLarge Network Problem
Posted by Legacy on 10/19/2001 12:00amOriginally posted by: Schuster, CP
ReplyLocal drives not Alphabetical order..
Posted by Legacy on 09/06/2001 12:00amOriginally posted by: BwB
Folders listed under local drives on my machine (mainly my C drive, which is the only local one I have) are not listed in alphabetical order. I'm running Win2k Professional. Its very annoying and difficult to select a folder when you have to look through the entire list to find the one you want...
Anyone have a fix for this?
ReplyI keep getting error at compile
Posted by Legacy on 01/07/2001 12:00amOriginally posted by: David Gosbee
Linking...
Reply.\PathPicker.lib : fatal error LNK1106: invalid file or disk full: cannot seek to 0x3749f77a
Error executing link.exe.
Can anyone help?
thanx.
Error.. at cancel
Posted by Legacy on 12/06/2000 12:00amOriginally posted by: Cho
Thanks for good source code.
But I have a question for your code.
I have met the same error whenever I push the
cancel butten without any directory selected.
Could you fix the error?
ReplyDouble clicking on a directory.
Posted by Legacy on 05/17/2000 12:00amOriginally posted by: Shlomi Ben-Zvi
ReplyWhy do i get these errors?
Posted by Legacy on 05/10/2000 12:00amOriginally posted by: Andreas H
Hi!
I tried your function here because it sounds so great, it
was just what i had been looking for. I added the files to my project like in method one. But when i try to compile later i get this error messages:
DlgGetPath.obj : error LNK2001: unresolved external symbol _WNetCloseEnum@4
DlgGetPath.obj : error LNK2001: unresolved external symbol _WNetEnumResourceA@16
DlgGetPath.obj : error LNK2001: unresolved external symbol _WNetOpenEnumA@20
Debug/PlayList.exe : fatal error LNK1120: 3 unresolved externals
Error executing link.exe.
Im running VC++6.
ReplyPlease help me i kind of got a deadline on this project!
Thanks in Advance / Andreas
Some updates to version 2.0
Posted by Legacy on 04/17/2000 12:00amOriginally posted by: Chris S.
Sorting can be done easily by adding
> if (bGotChildren)
> m_Tree.SortChildren(hParent);
into PopulateTree, if (hParent == m_hNetworkRoot) .. else if .. else, directly after while (bWorking)
Where is SetPath()-function ? added myself:
> void SetPath( CString sPath) { m_sPath = sPath; }
Display recycle bin:
add into PopulateTree, while (bWorking), if (finder.IsDirectory())
> bool bRecycleDir = finder.GetFileName() == "RECYCLED" && finder.IsSystem();
modify the following InsertItem(..)-call (or introduce a #define-constant DIR_RECYCLE or whatever)
> InsertItem( hParent, NULL, finder.GetFileName(), (bRecycleDir ? 15 : DRIVE_NO_ROOT_DIR), (bRecycleDir ? 15 : DRIVE_UNKNOWN) );
Image No. 15 (added by me) is an image of the bin as it is displayed by the Windows explorer
Possibility to hide the recycle bin
add bool m_bHideRecycleBin, let the constructor set a default value
add into PopulateTree, while (bWorking), if (finder.IsDirectory()) after bool bRecycleDir = ..
> if (!bRecycleDir || !m_bHideRecycleBin)
> { InsertItem(..); bGotChildren = true; } /*old stuff*/
Reply
Loading, Please Wait ...