SHBrowseForFolderA
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: SHBrowseForFolderA

  1. #1
    Join Date
    Feb 2006
    Posts
    3

    SHBrowseForFolderA

    I am using SHBrowseForFolderA for showing a file dialog. The length of the selected path id geeting trimmed.

    I've used these flags
    bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_STATUSTEXT;

    Is there any way by which i can increase the size of the label in the dilaog box for the currently selected path.

    ---Arun.

  2. #2
    Join Date
    Jan 2007
    Posts
    2

    Re: SHBrowseForFolderA

    Use CFileDialog class in MFC for browsing a file; For selecting a folder you can use the following code

    char Path[MAX_PATH];
    BROWSEINFO Browse;

    Browse.hwndOwner = m_hWnd; // Handle
    Browse.pidlRoot = NULL;
    Browse.pszDisplayName = Path;
    Browse.lpszTitle = "Choose";
    Browse.ulFlags = BIF_RETURNONLYFSDIRS; // Chnge it to yours flags
    Browse.lpfn = NULL;
    Browse.lParam = 0;
    Browse.iImage = 0;
    Browse.pidlRoot = SHBrowseForFolder(&Browse);
    SHGetPathFromIDList(Browse.pidlRoot, Path);

  3. #3
    ovidiucucu's Avatar
    ovidiucucu is offline Moderator/Reviewer Power Poster
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,021

    Re: SHBrowseForFolderA

    To get rid of long paths truncation, you have to rearrange a little the static controls which display the title and path, respectively. Once you are using BIF_STATUSTEXT style I can presume that you already use an application-defined callback function (e.g. BrowseCallbackProc). Here is an example, that rearrange those static texts by handling BFFM_INITIALIZED message:
    Code:
    #define IDC_STATIC_TITLE 0x3742
    #define IDC_STATIC_DIR   0x3743
    // ...
    int CALLBACK BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM lpData)
    {
       // ...
       switch(uMsg)
       {
       case BFFM_INITIALIZED:
          {
             CWnd* pDlg   = CWnd::FromHandle(hwnd);
             CWnd* pTitle = pDlg->GetDlgItem(IDC_STATIC_TITLE);
             CWnd* pDir   = pDlg->GetDlgItem(IDC_STATIC_DIR);
    
             // get the initial positions
             CRect rcTitle, rcDir;
             pTitle->GetWindowRect(rcTitle);
             pDir->GetWindowRect(rcDir);
             pDlg->ScreenToClient(rcTitle);
             pDlg->ScreenToClient(rcDir);
    
             // now re-arrange
             const int nHeight = rcDir.Height();
             rcTitle.bottom = rcTitle.top + nHeight;
             rcDir.top = rcTitle.bottom;
             rcDir.bottom = rcDir.top + 2 * nHeight;
             pTitle->MoveWindow(rcTitle);
             pDir->MoveWindow(rcDir);
    
             // NOTE: above it's just an example.
             //       to be shorter and clearer, no error checking is made.
             // ...       
          }
          break;
          // ...
       }
       return 0;
    }
    Code:
    // ...
          BROWSEINFO bi;
          // ...
          bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_STATUSTEXT;
          bi.lpfn = BrowseCallbackProc;
          // ...
    // ...
    Last edited by ovidiucucu; January 31st, 2007 at 03:23 AM. Reason: Oups! Forgot IDC_STATIC_TITLE and IDC_STATIC_DIR defines
    Ovidiu Cucu
    "When in Rome, do as Romans do."
    Visit: Microsoft Virtual Academy
    Follow: https://twitter.com/#!/ovidiucucu
    My blog: http://codexpert.ro/blog/author/ovidiu-cucu/

  4. #4
    ovidiucucu's Avatar
    ovidiucucu is offline Moderator/Reviewer Power Poster
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,021

    Re: SHBrowseForFolderA

    @to fazilvp:
    Your answer does not solve the OP problem:
    Quote Originally Posted by arunperi
    I am using SHBrowseForFolderA for showing a file dialog. The length of the selected path is geeting trimmed.
    [...]
    Is there any way by which i can increase the size of the label in the dilaog box for the currently selected path.
    Please, read a little bit more carefully a question before giving an answer!

    Thanks,
    Ovidiu

  5. #5
    Join Date
    Feb 2006
    Posts
    3

    Re: SHBrowseForFolderA

    Thanks Ovidiu for that.

    If i need to re-size ok and cancel buttons i need the $defines for them too, can you please list the #defines for "Ok" and "CANCEL" buttons.

    Thanks,
    Arun.

  6. #6
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,352

    Re: SHBrowseForFolderA

    IDOK and IDCANCEL

Posting Permissions

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


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center