//下面是回调函数,以及函数的处理 int CALLBACK _SHBrowseForFolderCallbackProc(HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM lpData) { static HWND hWndEdit = NULL; CString strDir; switch (uMsg) { case BFFM_INITIALIZED: { ::SendMessage(hwnd, BFFM_SETSELECTION, TRUE, lpData); CRect rect; HWND hChild = GetWindow(hwnd, GW_CHILD); while (hChild) { TCHAR szClass[256]; GetClassName(hChild, szClass, 255); // 如果是中间的树目录控件,使可以随窗口移动大小 if (strcmp(szClass, "Edit") == 0) { hWndEdit = hChild; } hChild = GetNextWindow(hChild, GW_HWNDNEXT); } SetWindowText(hwnd, "文件浏览..."); } break; case BFFM_SELCHANGED: if(hWndEdit) { if(::SHGetPathFromIDList((LPITEMIDLIST)lParam, strDir.GetBufferSetLength(MAX_PATH))) { SetWindowText(hWndEdit, strDir); } else { SetWindowText(hWndEdit, NULL); SendMessage(hwnd, BFFM_VALIDATEFAILED, 0, 0); } strDir.ReleaseBuffer(); } break; default: break; } return 0; } void CKKLUAScanDlg::OnRecogdir() { BROWSEINFO struBrowInfo; struBrowInfo.hwndOwner = this->GetSafeHwnd(); struBrowInfo.pidlRoot = NULL; TCHAR pFolderName[255]; TCHAR pFolder[255]; struBrowInfo.pszDisplayName = NULL; struBrowInfo.lpszTitle = _T("请选择您要打开的目录"); struBrowInfo.ulFlags = BIF_DONTGOBELOWDOMAIN | BIF_RETURNONLYFSDIRS | BIF_NEWDIALOGSTYLE | BIF_USENEWUI; struBrowInfo.lpfn = _SHBrowseForFolderCallbackProc; struBrowInfo.lParam = NULL; struBrowInfo.iImage = 0; LPCITEMIDLIST lpItemList; lpItemList = SHBrowseForFolder(&struBrowInfo); if(!SHGetPathFromIDList(lpItemList,pFolder)) { return; } CString strDir = pFolder; }