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
浙公网安备 33010602011771号