locked
SHBrowseForFolder bug in Windows 7? RRS feed

  • Question

  • I use BFFM_SETSELECTION and BIF_NEWDIALOGSTYLE in the code below. 
    In XP and Vista this selects the folder and scrolls the list to make the selected folder visible to the user.

    In Windows 7 the list is not scrolled to show the selected folder.

    Is there a workaround? (without removing BIF_NEWDIALOGSTYLE)




    int CALLBACK BrowseCallbackProc(HWND hWnd,UINT uMsg, LPARAM, LPARAM ) {
    
      TCHAR szDir[MAX_PATH+1];
    
      switch(uMsg) {
    
        case BFFM_INITIALIZED:       
    
             if( ::GetCurrentDirectory( MAX_PATH, szDir))
    
               ::SendMessage(hWnd,BFFM_SETSELECTION,true,(LPARAM)szDir);
    
             break;
    
       }
    
       return 0;
    
    }
    
    
    
    bool BrowseForFolder( HWND hParent, LPTSTR szOutPath )
    
    {
    
      bool bSelected = false;                 
    
    
    
      { /* Gets the Shell's default allocator */
    
        LPMALLOC pMalloc;
    
        if( SUCCEEDED(::SHGetMalloc(&pMalloc)) ) {
    
          BROWSEINFO bi;  ZeroMemory(&bi,sizeof(bi));
    
          bi.hwndOwner = hParent;
    
          bi.ulFlags  = BIF_NEWDIALOGSTYLE    |                    
    
                        BIF_RETURNFSANCESTORS | 
    
                        BIF_RETURNONLYFSDIRS;                                        
    
          bi.lpfn = BrowseCallbackProc;
    
    
    
          LPITEMIDLIST pidl = ::SHBrowseForFolder(&bi);
    
          if( pidl ) {
    
            bSelected = ::SHGetPathFromIDList(pidl,szOutPath)!=0;
    
            pMalloc->Free(pidl); // Free the PIDL allocated by SHBrowseForFolder.
    
          }
    
          pMalloc->Release(); // Release the shell's allocator.
    
        }
    
      }
    
      return bSelected;
    
    }
    
    
    Wednesday, November 25, 2009 1:17 PM

Answers

  • Hello Gaute,

    I have reported a feedback through Visual Studio & .NET Connect site:

    https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=518103

    This issue will be routed to the product unit who works on this specific feature area for triage and resolution. I’ll paste all responses from the product unit in this thread. And you also can click the link and add the feedback to your watchlist ( you need to log in using your account) so that you can get informed as soon as product units respond.  It may be some time before we get response from product unit. Please be patient.

    Thanks,
    Rong-Chun Zhang
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg@microsoft.com
    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.
    Friday, December 4, 2009 11:53 AM

All replies

  • Your code works for me correctly on Windows 7. Try my app (click left button on dialog).
    Wednesday, November 25, 2009 2:29 PM
  • Hello Gaute,

    Thanks for your post.

    I can reproduce this issue on my side with your code on Windows 7. I will discuss this with product team to see of there is any workaround for this. I will be back to you as soon as possible.

    Thanks,
    Rong-Chun Zhang
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg@microsoft.com
    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.
    Thursday, November 26, 2009 8:13 AM
  • Strange, why I cannot see this behavior under Windows 7.
    Thursday, November 26, 2009 10:50 AM
  • I downloaded your "Try my app" and it fails to scroll down to show the selected folder (Win 7 Ultimate x64).
    Thursday, November 26, 2009 12:01 PM
  • I've tried on Windows 7 32 bit. Maybe occurs only on 64 bit.
    Thursday, November 26, 2009 12:05 PM
  • Hello Nikita,

    I also tried it on 32bit Win7, the issue continues. I will keep discussing with product team and I will be back as soon as possible.

    Thanks,
    Rong-Chun Zhang
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg@microsoft.com
    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.
    Friday, November 27, 2009 10:47 AM
  • Hello Gaute,

    I have reported a feedback through Visual Studio & .NET Connect site:

    https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=518103

    This issue will be routed to the product unit who works on this specific feature area for triage and resolution. I’ll paste all responses from the product unit in this thread. And you also can click the link and add the feedback to your watchlist ( you need to log in using your account) so that you can get informed as soon as product units respond.  It may be some time before we get response from product unit. Please be patient.

    Thanks,
    Rong-Chun Zhang
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg@microsoft.com
    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.
    Friday, December 4, 2009 11:53 AM
  • Hello Gaute,

    I have reported a feedback through Visual Studio & .NET Connect site:

    https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=518103

    This issue will be routed to the product unit who works on this specific feature area for triage and resolution. I’ll paste all responses from the product unit in this thread. And you also can click the link and add the feedback to your watchlist ( you need to log in using your account) so that you can get informed as soon as product units respond.  It may be some time before we get response from product unit. Please be patient.

    Thanks,
    Rong-Chun Zhang
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg@microsoft.com
    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.
    这个问题在我电脑上也重现了,我现在是Win7 x86 sp1,但从我用WIN7 Beta开始一直有这个问题。看您的ID应该是个中国人,我英语不好,所以直接打中文了。
    如楼上所说,ulFlags需要用BIF_USENEWUI才会有这个问题,传统风格对话框不会
    Sunday, April 24, 2011 9:52 AM
  • Yes, there's a workaround, although it's not perfect.  I found it, with the help of a good friend, yesterday.  The only 100% solution I've found so far is to send a TVM_ENSUREVISIBLE to the tree, using TVM_GETNEXTITEM/TVGN_CARET, from BFFM_SELCHANGED. That works. Every time. On those random occasions when the pre-selected item isn't initially visible, there is the apparent scrolling after the dialog displays.

    Shame on Microsoft for pleading an inability to reproduce this!  Or for neglecting to fix it all these years!


    .NET: It's About Trust!
    http://vfred.mvps.org

    Tuesday, April 3, 2012 4:28 PM
  • I had the same problem, and when "experimenting" with the flags I could "solve" this by setting additional BIF_VALIDATE. In this case setting the path succeded.

    In my special case I tried to use the FolderBrowserDialog in WPF (for Win7 64 Bit) where you can give an initial path by setting FolderBrowserDialog.SelectedPath. This path was added and selected, but the selection was outside the visible area. So I was forced to handle this by calling SHBrowseForFolder, and selecting the path by calling SendMessage (the parameter handling is a little bit different for WPF) with BFFM_SETSELECTION.

    The selection now works (with additional BIF_VALIDATE) but the selection was still outside the visible area.That's now my next working item. :-)



    • Edited by AllesOnline Saturday, April 20, 2013 8:54 AM
    Saturday, April 20, 2013 8:52 AM