Solved

Selecting default folder in "Browse For Folder" Dialog

Posted on 2008-10-13
2
1,783 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

707 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