Solved

Selecting default folder in "Browse For Folder" Dialog

Posted on 2008-10-13
2
1,777 Views
Last Modified: 2013-11-20
Hi,

How can I select the default folder in my "Browse For Folder" dialog box (SHBrowseForFolder) ?

I have only found the way to set the default ROOT of my list by initializing the pidlRoot member of the BROWSEINFO structure.

Any way to to this ?
CString BrowseForFolder(HWND hWnd, LPCTSTR lpszStartFolder, LPCTSTR lpszSelectFolder, CString *pstrDisplayName, BOOL bGetSubFolderOnly)

 {

  char       szPath[MAX_PATH] = "";

  char       szDisplayName[MAX_PATH];

  BROWSEINFO stBI;
 

  stBI.hwndOwner      = hWnd;

  stBI.pidlRoot       = NULL;

  stBI.lpszTitle      = NULL;

  stBI.ulFlags        = BIF_RETURNONLYFSDIRS | BIF_EDITBOX | BIF_NEWDIALOGSTYLE;

  stBI.lpfn           = NULL;

  stBI.lParam         = 0;

  stBI.pszDisplayName = szDisplayName;
 

  if ( lpszStartFolder && lpszStartFolder[0] )

   {

    LPITEMIDLIST  pIDL = NULL;

    IShellFolder *pDesktopFolder;
 

    if ( SUCCEEDED(SHGetDesktopFolder(&pDesktopFolder)) )

     {

      strcpy(szPath, lpszStartFolder);
 

      OLECHAR olePath[MAX_PATH];
 

      MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, szPath, -1, olePath, MAX_PATH);
 

      ULONG nEaten;

      ULONG nAttributes;
 

      pDesktopFolder->ParseDisplayName(NULL, NULL, olePath, &nEaten, &pIDL, &nAttributes);
 

      pDesktopFolder->Release();

     }
 

    stBI.pidlRoot = pIDL;

   }
 

  if (lpszSelectFolder)

   {

    // TO DO

   }
 

  LPITEMIDLIST pstIIL = SHBrowseForFolder(&stBI);

  

  if (!pstIIL) return "";

  

  BOOL bRet = SHGetPathFromIDList(pstIIL, szPath);
 

  if (!bRet) return "";
 

  PathAddBackslash(szPath);

  

  int nIndex = 0;

  

  if (bGetSubFolderOnly && lpszStartFolder) nIndex = strlen(lpszStartFolder);

  

  return (szPath + nIndex);

 }

Open in new window

0
Comment
Question by:mike_marquet
2 Comments
 
LVL 19

Accepted Solution

by:
alb66 earned 125 total points
ID: 22701668
You need to use the callback procedure:
look at
http://msdn.microsoft.com/en-us/library/aa921328.aspx

here you can find a sample:
http://www.nirsoft.net/vc/brfolder.html
0
 

Author Closing Comment

by:mike_marquet
ID: 31505563
Thanks
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now