// szFilters is a text string that includes two file name filters: // "*.my" for "MyType Files" and "*.*' for "All Files." char szFilters[]= "MyType Files (*.my)|*.my|All Files (*.*)|*.*||"; // Create an Open dialog; the default file name extension is ".my". CFileDialog fileDlg (TRUE, "my", "*.my", OFN_FILEMUSTEXIST| OFN_HIDEREADONLY, szFilters, this);
// Display the file dialog. When user clicks OK, fileDlg.DoModal() // returns IDOK. if( fileDlg.DoModal ()==IDOK ) { CString pathName = fileDlg.GetPathName();
// Implement opening and reading file in here. ... //Change the window's title to the opened file's title. CString fileName = fileDlg.GetFileTitle (); } 其中 CFileDialog fileDlg (TRUE,...);//这个TRUE改为FALSE时就是保存
// "*.my" for "MyType Files" and "*.*' for "All Files."
char szFilters[]=
"MyType Files (*.my)|*.my|All Files (*.*)|*.*||"; // Create an Open dialog; the default file name extension is ".my".
CFileDialog fileDlg (TRUE, "my", "*.my",
OFN_FILEMUSTEXIST| OFN_HIDEREADONLY, szFilters, this);
// Display the file dialog. When user clicks OK, fileDlg.DoModal()
// returns IDOK.
if( fileDlg.DoModal ()==IDOK )
{
CString pathName = fileDlg.GetPathName();
// Implement opening and reading file in here.
...
//Change the window's title to the opened file's title.
CString fileName = fileDlg.GetFileTitle ();
}
其中
CFileDialog fileDlg (TRUE,...);//这个TRUE改为FALSE时就是保存