theEagles

I am sailing, to be with you, to be free.
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

MFC 文件夹浏览

Posted on 2012-09-17 15:16  theEagles  阅读(288)  评论(0)    收藏  举报

 

 

  void CCATEngineAppDlg::OnCustomizeBinlogsDir()
{
   CString strBinLogs = CxApplicationINI::Instance()->GetProfileString(_T("Logger Settings"), _T("BinLogsDirectory"), _T(""));

   BROWSEINFO   bi; 
   TCHAR   dispname[MAX_PATH],   path[MAX_PATH]={0};       
   ITEMIDLIST* pidl;
   ZeroMemory(&bi,sizeof(BROWSEINFO));
   bi.hwndOwner   =   GetSafeHwnd();
   bi.pidlRoot   =   0;       
   bi.pszDisplayName   =   dispname;       
   bi.lpszTitle   =   _T("Customize Bin Logs directory"); 
   bi.ulFlags   =   BIF_USENEWUI | BIF_RETURNONLYFSDIRS | BIF_VALIDATE | BIF_STATUSTEXT;;       
   bi.lpfn   =   BrowseCallbackProc;       
   bi.lParam   =   (LPARAM)(strBinLogs.GetString());       
   bi.iImage   =   0;     
   if (pidl = SHBrowseForFolder(&bi))//弹出文件夹浏览窗口,并选取目录  
   {
      if(SHGetPathFromIDList(pidl,path))   
      {
         strBinLogs = (LPCTSTR)path;
         CxApplicationINI::Instance()->WriteProfileString(_T("Logger Settings"), _T("BinLogsDirectory"), strBinLogs);
         CxApplicationINI::Instance()->FlushData();
         
         CreateDirectory(strBinLogs.GetString(), NULL);
         theLogger->SetLogsFolder(strBinLogs+_T("\\"));
      }
      UpdateData(FALSE);
   }
}

 

BrowseCallbackProc

typedef int ( CALLBACK *BrowseCallbackProc)(
HWND hwnd,
UINT uMsg,
LPARAM lParam,
LPARAM lpData
);

这个函数是当 SHBrowseForFolder 函数弹出Browse For Folder对话框后,应用程序响应该对话框消息的函数。

有四种消息:

   
BFFM_INITIALIZED 对话框已经完成初始化
BFFM_IUNKNOWN An IUnknown interface is available to the dialog box.
BFFM_SELCHANGED The selection has changed in the dialog box.
BFFM_VALIDATEFAILED The user typed an invalid name into the dialog's edit box. A nonexistent folder is considered an invalid name.

 

 

 

 

 

 

 

其他的参考文章:

http://www.cnblogs.com/Clingingboy/archive/2011/04/16/2018284.html