Click here to Skip to main content
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 1: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 245
1 Kamal Rocks 184
2 Sergey Alexandrovich Kryukov 175
3 BillWoodruff 173
4 PIEBALDconsult 160
0 OriginalGriff 5,655
1 DamithSL 4,506
2 Maciej Los 3,997
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,180


Advertise | Privacy | Mobile
Web02 | 2.8.141216.1 | Last Updated 27 Jun 2012
Copyright © CodeProject, 1999-2014
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