Home Page | Software | Support | Sales | Contact | About Us | News | Links | Czech Cesky | Spanish Espanol

CSHBrowseFolder Class
simplify folder selection

Download Download


1 extremely simple and small
2 class and function models
3 callback implemented
4 free with full source

Requirements: Windows 32bit, Visual C++ 5.0 (SP3 recommended)

Folder selector utility for Visual C++ that provides simple way to select folder the in applications developped in Visual C++. Object and funtion based versions are available, all with callback support.

This utility is free with full source open.

To set up you application or library to work with this class:
- Copy SHBrowseFolder.h and SHBrowseFolder.cpp files to your project directory
- Include SHBrowseFolder.h and SHBrowseFolder.cpp files in your project
- In stdafx.h or similar file, include shlobj.h file
- In stdafx.h or in your source file, include SHBrowseFolder.h file
- Call the selector using the syntax:
CSHBrowseFolder(m_hWnd).DoModal(pszPath, pszTitle);

- m_hWnd is parent window handle and may be NULL
- pszPath sends and receives full path selected
- pszTitle will display the title of the tree

DoModal method returns 'pidle' or NULL if selection was canceled.
See SHBrowseForFolder and SHGetPathFromIDList API functions and BROWSEINFO structure for more information.
See the example dialog methods OnSimple and OnAction to see the implementation.

CSHBrowseFolder::CSHBrowseFolder(HWND hwndOwner, UINT uiFlags =/* BIF_RETURNONLYFSDIRS*/)
- hwndOwner is a handle, CWnd-derived class may use m_hWnd member or *this (calls conversion to HWND)
- uiFlags default parameter may be ORed with BIF_STATUSTEXT to display current selection or any other text

LPITEMIDLIST CSHBrowseFolder::DoModal(char *pszPath, const char *pszTitle, char *pszDisplayName/* = 0*/)
- pszPath sends and receives the full path of the selection or is NULL
- pszTitle may point to text or CString using resource ID
- pszDisplayName receives name of the item selected or is NULL

int WINAPI CSHBrowseFolder::BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM lpData)
- callback procedure that handles only initialization to setup default folder and selection change to update the status
- may be extended to enable or disable OK button when item selection changes, etc.

There's abother one implemetaion in this project. See files BrowseFolder.h and BrowseFolder.cpp, and the function:
LPITEMIDLIST BrowseFolder(HWND hwndOwner, char *pszPath, const char *pszTitle, UINT uiFlags = BIF_RETURNONLYFSDIRS, char *pszDisplayName = 0);
- arguments description is the same, only include these files instead of SHBrowseFolder.h and SHBrowseFolder.cpp
- call the function similary like in commented versions of OnSimple and OnAction methods

Open Source

2004 Jakub Sika. All rights reserved.
Last modified: 14.10.2005 15:40