CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10
  1. #1
    Join Date
    Mar 2009
    Posts
    19

    FolderBrowserDialog in MFC

    Hi,

    I'm building MFC application and i'd like to use FolderBrowserDialog...but it seems there isn't a control in the toolbox with this name like C# and VB...

    Is there any other options???

    Thanks

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: FolderBrowserDialog in MFC

    Use SHBrowseForFolder API.
    Victor Nijegorodov

  3. #3
    Join Date
    Mar 2009
    Posts
    19

    Re: FolderBrowserDialog in MFC

    well i tried to use CFileDialog but i'm sure this is not the best way as i have to select the file included in the folder then i get the folder name...

    CFileDialog fileDlg(TRUE, NULL, NULL, 4|2, 0, this, NULL);
    if (fileDlg.DoModal() == IDOK)
    {
    CString FolderName = fileDlg.GetFolderPath();
    }

    also i got an error in this command "Command Assertion Failed" !!!

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: FolderBrowserDialog in MFC

    Quote Originally Posted by Fouly View Post
    well i tried to use CFileDialog but i'm sure this is not the best way ...
    Exactly!
    But didn't you read my answer to you?
    Again:
    Quote Originally Posted by Victor
    Use SHBrowseForFolder API.

    Quote Originally Posted by Fouly View Post
    also i got an error in this command "Command Assertion Failed" !!!
    Where?
    Did you press the Retry button to debug your code and see the reason of the "Assertion Failed"?
    Victor Nijegorodov

  5. #5
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,637

    Re: FolderBrowserDialog in MFC

    Quote Originally Posted by Fouly View Post
    well i tried to use CFileDialog but i'm sure this is not the best way as i have to select the file included in the folder then i get the folder name...

    CFileDialog fileDlg(TRUE, NULL, NULL, 4|2, 0, this, NULL);
    if (fileDlg.DoModal() == IDOK)
    {
    CString FolderName = fileDlg.GetFolderPath();
    }

    also i got an error in this command "Command Assertion Failed" !!!
    Perhaps you missed Victor's post.


    From MSDN, about GetFolderPath(). "The dialog box must have been created with the OFN_EXPLORER style; otherwise, the method will fail with an assertion."

  6. #6
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: FolderBrowserDialog in MFC

    Quote Originally Posted by Fouly View Post
    CFileDialog fileDlg(TRUE, NULL, NULL, 4|2, 0, this, NULL);
    And what does this parameter ( 4|2 ) mean?
    Victor Nijegorodov

  7. #7
    Join Date
    Mar 2009
    Posts
    19

    Resolved Re: FolderBrowserDialog in MFC

    OH!!! sorry VictorN i didn't read ur message before posting i forgot to refresh :$

    Thanks a lot for your help it worked

  8. #8
    Join Date
    Feb 2002
    Posts
    3,788

    Re: FolderBrowserDialog in MFC

    Quote Originally Posted by victorn View Post
    and what does this parameter ( 4|2 ) mean?
    4/2 = 2/1 = 2

  9. #9
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: FolderBrowserDialog in MFC

    Quote Originally Posted by Alin View Post
    4/2 = 2/1 = 2

    But there is a pipe, not a slash between 4 and 2.
    Victor Nijegorodov

  10. #10
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,150

    Re: FolderBrowserDialog in MFC

    Maybe he finds it easier to use numerical constants instead of names like OFN_OVERWRITEPROMPT
    Marc Gregoire - NuonSoft (http://www.nuonsoft.com)
    My Blog
    Wallpaper Cycler 3.5.0.97

    Author of Professional C++, 4th Edition by Wiley/Wrox (includes C++17 features)
    ISBN: 978-1-119-42130-6
    [ http://www.facebook.com/professionalcpp ]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured