最新的WTL库中添加了对Vista/Win7新风格文件对话框API的封装,使用起来非常方便。
//#include <atldlgs.h>
COMDLG_FILTERSPEC filterSpecs[] ={{_T("Text documents(*.txt)"),_T("*.txt")},{_T("MS Word documents(*.doc|*.docx)"),_T("*.doc;*.docx")},{_T("All documents(*.*)"),_T("*.*")}};CShellFileOpenDialog fileOpenDlg(NULL,FOS_FORCEFILESYSTEM|FOS_FILEMUSTEXIST|FOS_PATHMUSTEXIST,_T("txt"),
filterSpecs,_countof(filterSpecs));fileOpenDlg.DoModal(m_hWnd);CString filePath;fileOpenDlg.GetFilePath(filePath);//MessageBox(filePath,_T("File path"),MB_OK|MB_ICONINFORMATION);
CShellFileOpenDialog fileOpenDlg(NULL,FOS_FORCEFILESYSTEM|FOS_PATHMUSTEXIST|FOS_PICKFOLDERS);fileOpenDlg.DoModal(m_hWnd);CString folderPath;fileOpenDlg.GetFilePath(folderPath);MessageBox(folderPath,_T("Folder path"),MB_OK|MB_ICONINFORMATION);