Click here to Skip to main content
13,248,089 members (40,798 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


7 bookmarked
Posted 7 May 2012


, 7 May 2012
Rate this:
Please Sign up or sign in to vote.
Microsoft don't have a nice interface that used to select a specify folder.

Microsoft don't have a nice interface that used to select a specify folder. First, I search some code on the internet, but they don't work perfectly. So, I changed these code, and they become my FolderBrowser.

The class CFolderBrowser only has a static method, called SelectFolder. So you can call it without creating an object of FolderBrowser. In fact, we can just use a c style function to implent it. The core code of SelectFolder, call windows's Shell API.

  • SHGetSpecialFolderLocation(): It can get the Desktop's path.
  • SHBrowseForFolder(): It can show the window to select folder.
  • SHGetPathFromIDList(): It can get the selected folder as a string.

SHBrowseForFolder need the struct BROWSEINFO 's pointer as its parameter. All the input info can be found in BROWSEINFO. The lpfn member can accept a callback function. When the user open the selecting window or select any folder, lpfn will be called. So, we can use the callback function to set the initial path, and change the title when user select any folder.

The API SetCurrentDirectory(), can save the current folder. So, when you select folder next time, GetCurrentDirectory() can get the saved folder. You can use the current folder as the initial path, or not, as you like.

At last, the example code:

CString strPath;
::GetCurrentDirectory(MAX_PATH, strPath.GetBuffer(MAX_PATH));
if (CFolderBrowser::SelectFolder(this->m_hWnd, strPath))
 m_edit.SetWindowText(strPath);        // m_edit is an object of CEdit


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

United States United States
No Biography provided

You may also be interested in...

Comments and Discussions

GeneralMy vote of 5 Pin
Alien51230-Jul-12 6:17
memberAlien51230-Jul-12 6:17 
GeneralMy vote of 5 Pin
Volynsky Alex19-May-12 9:18
memberVolynsky Alex19-May-12 9:18 
QuestionDownloading does not work Pin
anlarke15-May-12 3:50
memberanlarke15-May-12 3:50 
AnswerRe: Downloading does not work Pin
liaoy74715-May-12 6:06
memberliaoy74715-May-12 6:06 

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.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.171114.1 | Last Updated 8 May 2012
Article Copyright 2012 by liaoy747
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid