WTL-Open file dialog of new vista/win7 style
时间:2010-09-17 来源:wudong
最新的WTL库中添加了对Vista/Win7新风格文件对话框API的封装,使用起来非常方便。
1.选择文件对话框:
//#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);

2.选择文件夹对话框
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);

相关阅读 更多 +