1.文件对话框的打开代码
CFileDialog dlg(TRUE , ".map" , NULL , OFN_HIDEREADONLY , "map文件(*.map)|*.map|所有文件(*.*) |*.*||" );
CString file_path;
CString temp_path;
if (dlg.DoModal() == IDOK) {
file_path = dlg.GetPathName();//获取文件的全路径
//file_path.Replace("\\","\\\\");//将/替换为//
file_path.Replace("\\","/");
temp_path.Format("%s%s",file_path.GetBuffer(1),"/");
}
<wbr> CFileDialog文件选择对话框的使用:<br style="line-height:22px"><wbr><wbr><wbr> 首先构造一个对象并提供相应的参数,构造函数原型如下:<br style="line-height:22px"><wbr><wbr><wbr> CFileDialog::CFileDialog(<br style="line-height:22px"><wbr><wbr><wbr><wbr><wbr><wbr><wbr> BOOL bOpenFileDialog, //为TRUE则显示打开对话框,为FALSE则显示保存对话文件对话框<br style="line-height:22px"><wbr><wbr><wbr><wbr><wbr><wbr><wbr> LPCTSTR lpszDefExt = NULL, //默认的文件扩展名<br style="line-height:22px"><wbr><wbr><wbr><wbr><wbr><wbr><wbr> LPCTSTR lpszFileName = NULL, //默认的文件名<br style="line-height:22px"><wbr><wbr><wbr><wbr><wbr><wbr><wbr> DWORD dwFlags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, //设定风格<br style="line-height:22px"><wbr><wbr><wbr><wbr><wbr><wbr><wbr> LPCTSTR lpszFilter = NULL, //列出可供选择的文件类型和相应的扩展名<br style="line-height:22px"><wbr><wbr><wbr><wbr><wbr><wbr><wbr> CWnd* pParentWnd = NULL //父窗口句柄指针<br style="line-height:22px"><wbr><wbr><wbr> );<br style="line-height:22px"><br style="line-height:22px"> LPCTSTR lpszFilter 参数格式如:"Chart Files (*.xlc)|*.xlc|Worksheet Files (*.xls)|*.xls|Da<wbr style="line-height:22px">ta Files (*.xlc;*.xls)|*.xlc;*.xls|All Files (*.*)|*.*||";文件类型说明和扩展名间用 | 分隔,同种类型文件的扩展名间可以用 ; 分割,每种文件类型间用 | 分隔,末尾用 || 指明。</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
2.文件夹浏览对话框的代码
TCHAR path[1024];