Path Picker with Network Capabilities

Sample Image

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.

  1. Copy the source files DlgGetPath.cpp and DlgGetPath.h to your Project directory and add them to your project.
  2. Change #include "PathPicker.h" to the name of your project as necessary.
  3. From within your project open the PathPicker.rc file and drag the Bitmap and Dialog into your project.
  4. 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() );
    	}
    }
    
Method 2 - Using the DLL. This method uses the DLL. It is a regular DLL so can also be used with inferior languages such as VB and Delphi. The following example is a simple static implementation however dynamic loading when the dialog is called is also possible.
  1. Link your project with PathPicker.lib and insert the following code where you want the dialog to appear.
  2. 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

Download source - 20 KB

History



Comments

  • Great stuff!!! Added a selection routine to select a given path

    Posted by bgsommerfeld on 03/27/2006 05:06pm

    I 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;
    }

    Reply
  • Help : Tree Item link to directory

    Posted by Legacy on 02/09/2004 12:00am

    Originally 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...

    Reply
  • Displaying files within directory???

    Posted by Legacy on 12/04/2001 12:00am

    Originally posted by: Maitri Venkat-Ramani

    How do you modify the code to display files in each directory???

    Thank you!!

    Reply
  • Large Network Problem

    Posted by Legacy on 10/19/2001 12:00am

    Originally posted by: Schuster, CP

    I have over a thousand listings in some network groups.
    
    When you would Open Network Neighborhood only about half of
    the computers in the group would show. The TRACE Message
    was "*** ERROR 0 - Cannot complete network drive
    enumeration" I looked up the WNetEnumResource and this
    function is meant to be called many times. One simple
    change fixes every thing.

    Function:
    bool CDlgGetPath::EnumNetwork( HTREEITEM hParent )

    Original Code Section:
    if( dwResult != ERROR_NO_MORE_ITEMS )
    {
    TRACE( _T("*** ERROR %d - Cannot complete network drive enumeration\n"), dwResult );
    break;
    }

    Replace with:
    if( dwResult != ERROR_NO_MORE_ITEMS && dwResult != NO_ERROR)
    {
    TRACE( _T("*** ERROR %d - Cannot complete network drive enumeration\n"), dwResult );
    dwResult = ERROR_NO_MORE_ITEMS;
    }

    This Lets the Do While Loop keep Looping Until All Items are Enumerated.

    Chris Schuster

    Reply
  • Local drives not Alphabetical order..

    Posted by Legacy on 09/06/2001 12:00am

    Originally 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?

    Reply
  • I keep getting error at compile

    Posted by Legacy on 01/07/2001 12:00am

    Originally posted by: David Gosbee

    Linking...
    .\PathPicker.lib : fatal error LNK1106: invalid file or disk full: cannot seek to 0x3749f77a
    Error executing link.exe.
    Can anyone help?
    thanx.

    Reply
  • Error.. at cancel

    Posted by Legacy on 12/06/2000 12:00am

    Originally 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?

    Reply
  • Double clicking on a directory.

    Posted by Legacy on 05/17/2000 12:00am

    Originally posted by: Shlomi Ben-Zvi

    I am trying to add a double clicking capability to the tree control so the user can
    
    select and exit the dialog in one action.

    I added the following line to BEGIN_MESSAGE_MAP

    ON_NOTIFY(NM_RDBLCLK, IDC_TREE, OnRdblclkTree)

    and the appropriate code to the OnRdblclkTree() function

    Unfortunately, I can't figure out why OnRdblclkTree never receives control.

    Thank you.

    Reply
  • Why do i get these errors?

    Posted by Legacy on 05/10/2000 12:00am

    Originally 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.
    Please help me i kind of got a deadline on this project!
    Thanks in Advance / Andreas

    Reply
  • Some updates to version 2.0

    Posted by Legacy on 04/17/2000 12:00am

    Originally 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 ...

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Learn How A Global Entertainment Company Saw a 448% ROI Every business today uses software to manage systems, deliver products, and empower employees to do their jobs. But software inevitably breaks, and when it does, businesses lose money -- in the form of dissatisfied customers, missed SLAs or lost productivity. PagerDuty, an operations performance platform, solves this problem by helping operations engineers and developers more effectively manage and resolve incidents across a company's global operations. …

  • Live Event Date: December 18, 2014 @ 2:00 p.m. ET / 11:00 a.m. PT The Internet of Things (IoT) incorporates physical devices into business processes using predictive analytics. While it relies heavily on existing Internet technologies, it differs by including physical devices, specialized protocols, physical analytics, and a unique partner network. To capture the real business value of IoT, the industry must move beyond customized projects to general patterns and platforms. Check out this upcoming webcast …

Most Popular Programming Stories

More for Developers

RSS Feeds