一、wtl中使用

(1)打开文件对话框
CFileDialog cFilePath( TRUE,NULL,NULL,OFN_SHAREAWARE,_T("VR Files (*.wrl)\0*.wrl\0All Files (*.*)\0*.*||")

);
WCHAR strBuffer[65535] = {0};
cFilePath.m_ofn.lpstrFile = strBuffer;
cFilePath.m_ofn.nMaxFile = 65535;
if( cFilePath.DoModal() == IDOK )
{
LPWSTR lpFilePath = cFilePath.m_ofn.lpstrFile;
}
(2)保存文件对话框
CFileDialog cFilePath(FALSE,"wrl",NULL,OFN_SHAREAWARE,_T("VR Files(*.wrl)\0*.wrl"));
char strBuffer[65535] = {0};
cFilePath.m_ofn.lpstrFile = strBuffer;
cFilePath.m_ofn.nMaxFile = 65535;
if( cFilePath.DoModal() == IDOK )
{
CComBSTR bstrFilePath(cFilePath.m_ofn.lpstrFile);
}

二.MFC中CFileDialog的使用

(1)打开文件对话框

(2)保存文件对话框
CFielDialog fileDlg(FALSE);
fileDlg.DoModal();
//改变对话框标题
fileDlg.m_ofn.lpstrTitle = "保存对话框";
//设置保存类型,即设置过滤器
//该字段是一个包含多个过滤字符串对的缓冲区的指针,各过滤字符串之间,以及字符串对内部两个字符串之间都

以"\0"分割,最后的过滤器字符串必须以两个"\0"字符结尾.
//第一个字符串描述过滤器,而第二个字符串表明过滤使用的文件扩展名称,多个扩展名称可以用分号(;)分割.
//如果把过滤字符串设置为"Text Files(*.txt)",那么该字符串只是出现在"另存为"对话框中保存类型列表中看

到的文字,并不具有过滤功能.如果要有过滤功能,必须在其后加上"\0"字符,并随后加上"*.txt"字符串.
fileDlg.m_ofn.lpstrFilter = "Text Files(*.txt)\0*.txt\0All Files(*.*)\0*.*\0\0";
//设置默认的扩展名
fileDlg.m_ofn.lpstrDefExt = "txt";