Click here to Skip to main content
11,639,499 members (69,451 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ MFC VS2010
Hi All,

I am working with C++ using VS 2010 MFC(WindowXP). Now I want to opem folder dialog(the same in C#) when click on button "Browser". I found out CFolderPickerDialog but It can not display dialog so I can choose a folder which I need.
CFolderPickerDialog  fFolder("C:\\", 0,NULL,0);
fFolder.DoModal()


Please help me.


thanks in advance.
Posted 12-Jun-12 0:53am
ngthtra1.4K
Comments
RDBurmon at 13-Jun-12 9:33am
   
Thanks Everyone who replied to this thread , So ngthra, I think you have got enough responses and you should be able to mark it as your answer and close the thread. Please do so.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Have a look at SHBrowseForFolder[^]
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

May be this link will help you Smile | :)


[^]

Thanks
  Permalink  
Comments
ngthtra at 15-Jun-12 7:16am
   
How to set default path when open folder dialog Using SHBrowseForFolder? because this code is set default path which it is desktop. and I want to it change.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

my solution:
inline static int CALLBACK BrowseCallbackProc(HWND hwnd,UINT uMsg, LPARAM lParam, LPARAM lpData)
{
  // If the BFFM_INITIALIZED message is received
  // set the path to the start path.
  switch (uMsg)
  {
    case BFFM_INITIALIZED:
    {
      if (NULL != lpData)
      {
        SendMessage(hwnd, BFFM_SETSELECTION, TRUE, lpData);
      }
    }
  }
  return 0; // The function should always return 0.
}
 

/*--------------------------------------------------------------------*/
/*  BrowseForFolder                                                   */
/*--------------------------------------------------------------------*/
/**
 *  @brief   open a folder dialog to choose folder
 *
 *  @param   HWND                 [in] is the parent window.
 *           szCurrent            [in] is an optional start folder. Can be NULL.
 *           szPath               [in] receives the selected path on success. Must be MAX_PATH characters in length.
 *
 *  @return  TRUE: open and return folder path which is choosed
 *           FALSE: can't open
 */
inline BOOL BrowseForFolder(HWND hwnd, LPCTSTR szCurrent, LPTSTR szPath)
{
 
  BROWSEINFO   bi = { 0 };
  LPITEMIDLIST pidl;
  TCHAR        szDisplay[MAX_PATH];
  BOOL         retval;
 
  CoInitialize(NULL); 
  if(szPath == NULL){
    szPath = szDisplay;
  }  
  bi.hwndOwner      = hwnd;
  bi.pszDisplayName = szDisplay;
  bi.lpszTitle      = TEXT("フォルダを選択してください。");
  bi.ulFlags        = BIF_RETURNONLYFSDIRS;
  bi.lpfn           = BrowseCallbackProc;
  bi.lParam         = (LPARAM) szCurrent; 
  // open browser folder dialog
  pidl = SHBrowseForFolder(&bi);
  if (NULL != pidl)
  {
    // get folder path
    retval = SHGetPathFromIDList(pidl, szPath);
    CoTaskMemFree(pidl);
  }
  else
  {
    retval = FALSE;
  }
  if (!retval)
  {
    szPath[0] = TEXT('\0');
  }
  CoUninitialize();
  return retval;
}
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 9,081
1 Sergey Alexandrovich Kryukov 8,812
2 Mika Wendelius 7,027
3 Suvendu Shekhar Giri 2,600
4 F-ES Sitecore 2,548


Advertise | Privacy | Mobile
Web02 | 2.8.150728.1 | Last Updated 27 Jun 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100