//选择文件框 void selectFile() { CString strSelectedFile; char szFileFilter[] = "文本文件|*.txt|源代码文件|*.c;*.cpp|所有文件|*.*|"; CFileDialog FileDialogBox(TRUE,NULL,"",OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,szFileFilter,this); if ( FileDialogBox.DoModal()==IDOK ) { strSelectedFile = FileDialogBox.GetPathName(); AfxMessageBox("你选择了文件:"+strSelectedFile); } } //选择目录框 void selectDirectory() { char szDir[MAX_PATH]={0}; BROWSEINFO bi={0}; bi.hwndOwner = this->m_hWnd; bi.pidlRoot = NULL; bi.pszDisplayName = szDir; bi.lpszTitle = "请选择目录"; bi.ulFlags = BIF_RETURNONLYFSDIRS; bi.lpfn = NULL; bi.lParam = 0; bi.iImage = 0; ITEMIDLIST* pidl = SHBrowseForFolder(&bi); if ( pidl == NULL ) { return; } if ( SHGetPathFromIDList(pidl, szDir) ) { AfxMessageBox("你选择了目录:"+szDir); } }