none
Browse dialog using BROWSEINFO ulFlags BIF_RETURNONLYFSDIRS won't work when BIF_NEWDIALOGSTYLE flag is used

    Question

  • I'm trying the use SHBrowseForFolder function, but when I use the BIF_NEWDIALOGSTYLE flag it seems to negate the BIF_RETURNONLYFSDIRS flag.

    browseInfo.ulFlags = BIF_RETURNONLYFSDIRS | BIF_NEWDIALOGSTYLE;

    How can I use both?

    Friday, July 23, 2010 3:44 PM

Answers

  • Thankyou very much for looking into this issue for me.  I'm surprised this issue has not been documented before.  My work around is to treat an OK button click when a non-folder is selected as a Cancel button click.

     

    Thank you again.

    Wednesday, July 28, 2010 3:13 PM

All replies

  • Hi DoubleDownHokie,

    I have tested the scenario you mentioned above, actually it works as expected.   As the description in MSDN Library,

    BIF_RETURNONLYFSDIRS (0x00000001)

    0x00000001. Only return file system directories. If the user selects folders that are not part of the file system, the OK button is grayed.

    BIF_NEWDIALOGSTYLE (0x00000040)

    0x0000004. Use the new user interface. Setting this flag provides the user with a larger dialog box that can be resized. The dialog box has several new capabilities, including: drag-and-drop capability within the dialog box, reordering, shortcut menus, new folders, delete, and other shortcut menu commands.

     I set the ulFlags to BIF_RETURNONLYFSDIRS | BIF_NEWDIALOGSTYLE. You can check the my screen cut. It clearly shows it use the new interface, and the OK button is gray when the selected folder is not part of the file system.

    http://cid-2826cf1126a90490.photos.live.com/self.aspx/ShareDoc/SCNpt.jpg

    The following is the code what I used to test. May be it helps to find some problem in you side.

    BROWSEINFO bi;
    ZeroMemory(&bi, sizeof(bi));
    TCHAR szDisplayName[MAX_PATH];
    szDisplayName[0] = '\0';
    bi.hwndOwner = NULL;
    bi.pidlRoot = NULL;
    bi.pszDisplayName = szDisplayName;
    bi.lpszTitle = TEXT("Browsing");
    bi.ulFlags = BIF_RETURNONLYFSDIRS|BIF_NEWDIALOGSTYLE;
    bi.lParam = NULL;
    bi.iImage = 0;
    SHBrowseForFolder(&bi);
    

    If you have any concern, please let me know.

    Cheers,

    Yi


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Monday, July 26, 2010 5:36 AM
    Moderator
  • Thank you for your response.  I ran the code you posted, and I get the same behavior as before.  The OK button is always enabled regardless of what is selected: folders as well as My Network Places , My Computer , etc....  Is there any other thing I need to check, use a special manifest, etc...

     

    Thanks.

    Monday, July 26, 2010 3:29 PM
  • Hi DoubleDownHokie,

    I don’t believe there are some secrets behind it. 

    If we just create a new MFC dialog based application, create a button handler, copy and paste above code into the handler, we build it and click the button. This way can help us check if it works with a simple environment.

    Cheers,

    Yi

     


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Tuesday, July 27, 2010 1:42 AM
    Moderator
  • I created a new MFC dialog based application with Visual Studio 2005 version 8.0.50727.762 SP.050727-7600 (using default settings with the wizard), added a button handler (OnBnClickedOk) and pasted your code in it.  I get the same thing; OK is always enabled on the folder dialog regardless of what is selected.
    Tuesday, July 27, 2010 2:37 PM
  • I tried a new MFC dialog with VC6 as well and got the same problem.
    Tuesday, July 27, 2010 3:51 PM
  • Hi DoubleDownHokie,

    You probably are correct.

    I tested this code in windows vista/7, it works. If I test it on windows XP, it doesn’t work. However, I didn’t find any documents about this issue. I have tried new windows SDK on windows XP, it doesn’t work, either.

    I recommend you post this issue to our Connect feedback portal. Our developer will evaluate them seriously and take them into consideration when designing future release or service pack of the Visual C++ or Windows XP.

     

    Improving the quality of our products and services is a never ending process for Microsoft.

     

    Thank you very much!

    Yi Feng Li


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Wednesday, July 28, 2010 3:51 AM
    Moderator
  • Thankyou very much for looking into this issue for me.  I'm surprised this issue has not been documented before.  My work around is to treat an OK button click when a non-folder is selected as a Cancel button click.

     

    Thank you again.

    Wednesday, July 28, 2010 3:13 PM
  • The following newsgroup thread might help which implies that you should change the state of the OK button yourself, using the callback and sending the message BFFM_ENABLEOK, and not rely on BIF_RETURNONLYFSDIRS when using the new UI styles for the BrowseForFolder dialog.

    https://groups.google.com/forum/#!topic/microsoft.public.win32.programmer.ui/7MW8EsuuH1E


    This may also be related to calling InitCommonControlsEx without the ICC_STANDARD_CLASSES flag. I recommend just using InitCommonControls and see if it resolves the problem in your case.
    • Edited by Nathan Moinvaziri Thursday, July 18, 2013 7:19 PM added more on initcommoncontrolsex
    Thursday, July 18, 2013 5:44 PM
  • Hi,

    I have used the same like

    SHBrowseForFolder(&bi); but which is failing to highlight the folder.

    it can able to open the folder bt selection is not there.

    I s there anything i have missed.

    BROWSEINFO bi;
    ZeroMemory(&bi, sizeof(BROWSEINFO));

    _TCHAR szPath[_MAX_PATH];

    LPTSTR pszPath = szPath;

    //Fill out bi structure
    bi.hwndOwner = m_hWnd;
    bi.pidlRoot  = NULL;
    bi.pszDisplayName = pszPath;
    bi.ulFlags = BIF_RETURNONLYFSDIRS| BIF_NEWDIALOGSTYLE;
    bi.lpfn = BrowseCallbackProc;

    //Assign target path to lParam, which is used for highlighting the folder
    _TCHAR szTargetPath[_MAX_PATH];
    GetDlgItem(IDC_FOLDER).GetWindowText(szTargetPath,_MAX_PATH);
    DWORD dwAttr = ::GetFileAttributes(szTargetPath);
    if( dwAttr != 0xFFFFFFFF && (dwAttr & FILE_ATTRIBUTE_DIRECTORY) )
    {
    bi.lParam = reinterpret_cast<LPARAM>(szTargetPath);
    }
    else
    {
    bi.lParam = reinterpret_cast<LPARAM>(m_strDestFolder.GetString());
    }
     
    //Invoke the Browse For Folder dialog
    LPITEMIDLIST pidl = SHBrowseForFolder(&bi);

    Post if anyone knows..

    Wednesday, November 20, 2013 8:39 AM