Click here to Skip to main content
11,479,951 members (43,804 online)
Click here to Skip to main content


, 7 Sep 2005 50.7K 1.7K 45
Rate this:
Please Sign up or sign in to vote.
Browse to a folder.

Sorry, it should have been FolderBrowse.jpg


File browsing in MFC is easy due to the included CFileDialog class. CFolderDlg wraps the SDK's SHBrowseForFolder function and makes folder browsing as easy as file browsing.


The programmer can specify an initial folder. The user can create new folders. The dialog is resizable.

Using the code

You can get the name of a user selected folder in three lines of code:

// create and initialize a new object
CFolderDlg dlg(TRUE, m_folder, this);

// show dialog
if (dlg.DoModal() == IDCANCEL) return;

// get selected folder
m_folder = dlg.GetFolderName();

If you want to give some extra information to the user, you can add the following line:

// set the text that is displayed above the tree view control
dlg.SetTitle("Any instructions...");

The CFolderDlg constructor looks like this:

CFolderDlg(BOOL HideNewFolderButton, 
        const CString& InitialFolder, CWnd* pParent);

Points of Interest

If you are using Microsoft Visual C++ 6.0 (as I am), you will have to upgrade your Software Development Kit (SDK):

  1. Download the ISO version.
  2. Use DAEMON Tools to install the SDK.
  3. Replace your include folders:





If your compiler can't find CoInitializeEx(), add #define _WIN32_DCOM to your stdafx.h.


Version 1.0


  • The programmer can specify an initial folder.
  • The user can create new folders.
  • The dialog is resizable.


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


About the Author

Achim Klein
Web Developer
Germany Germany
No Biography provided

Comments and Discussions

QuestionNice dialog box Pin
Gluups28-Jul-13 4:42
memberGluups28-Jul-13 4:42 
GeneralSome smoll Problem Pin
david bagaturia22-Feb-07 0:20
memberdavid bagaturia22-Feb-07 0:20 
GeneralNice! Pin
Abu Mami10-Dec-05 9:28
memberAbu Mami10-Dec-05 9:28 
GeneralAlternatives? Here are some: Pin
Andromeda Shun13-Sep-05 22:44
memberAndromeda Shun13-Sep-05 22:44 
GeneralRe: Alternatives? Here are some: Pin
Habeeballah6-Oct-05 2:16
memberHabeeballah6-Oct-05 2:16 
But non of those mentioned in the above comment, works on VC6 and they are not precise like the one over here. I challege that this article and the sample provided are so simple that anybody can easily adopt in their code.

Allah likes you more when you search for knowledge.
There is no substitute for Hard Work.

-- modified at 7:19 Thursday 6th October, 2005

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150520.1 | Last Updated 7 Sep 2005
Article Copyright 2005 by Achim Klein
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid