CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2004
    Posts
    28

    SHBrowseForFolder

    I need to use SHBrowseForFolder but have not been able to locate what I need to get the required behavior. It seems pretty simple, I need the routine to open as if the root of the dialog is the desktop so you see all the users drives, shares, etc. but I need to to open a folder. For example the user may be working in folder c:\A1, so when the folder dialog opens, you see all the drives, shares, etc, but the c:\A
    Nemo99

  2. #2
    Join Date
    Jan 2004
    Posts
    28

    Unhappy continued

    <hmmm, hit something on the keyboard and it submitted my question???> anyway, I need the c:\A1 directory to be open as the selected directory. Currently when I set the root, it does not show any directories above or at the same level as the root. So if I set c:\A1 as root, the user can only see directories below A1. Is there something simple I am missing, it seems what I am looking for would be the default behavior.

    Thanks in advance
    Nemo99

  3. #3
    Join Date
    Sep 1999
    Location
    Germany, Hessen
    Posts
    226
    As far as I remember there is no way, because that is the designed behavior of SHBrowseForFolder.

  4. #4
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,150
    It's possible by using a callback.
    Code:
    BROWSEINFO browseinfo;
    // Fill in your browseinfo
    ...
    // Add these
    browseinfo.lParam = reinterpret_cast<LPARAM>(pszFolder);
    browseinfo.lpfn = &SHBrowseForFolderCallbackProc;
    where pszFolder is a pointer to a TCHAR containing your folder to open.
    The callback function
    Code:
    int CALLBACK SHBrowseForFolderPIDLCallbackProc(HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM lpData)
    {
    	if (!lpData || !::IsWindow(hwnd))
    		return 0;
    
    	switch (uMsg)
    	{
    	case BFFM_INITIALIZED:
    		// Set the initial folder
    		::SendMessage(hwnd, BFFM_SETSELECTION, TRUE, lpData);
    		break;
    	}
    	return 0;
    }
    Change the TRUE in the sendmessage to FALSE when lpData is a PIDL.
    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