Visual c++ 如何在MFC中获得另存为对话框
如何在MFC中创建“另存为”对话框 例如,当我在MFC中单击“另存为”时,会出现一个对话框。我如何复制它?像这样:Visual c++ 如何在MFC中获得另存为对话框,visual-c++,mfc,save,Visual C++,Mfc,Save,如何在MFC中创建“另存为”对话框 例如,当我在MFC中单击“另存为”时,会出现一个对话框。我如何复制它?像这样: CFileDialog dlg(FALSE); dlg.DoModal(); 以下是MSDN中打开对话框的示例: void CMyClass::OnFileOpen() { // szFilters is a text string that includes two file name filters: // "*.my" for "MyType Files" an
CFileDialog dlg(FALSE);
dlg.DoModal();
以下是MSDN中打开对话框的示例:
void CMyClass::OnFileOpen()
{
// szFilters is a text string that includes two file name filters:
// "*.my" for "MyType Files" and "*.*' for "All Files."
TCHAR szFilters[]= _T("MyType Files (*.my)|*.my|All Files (*.*)|*.*||");
// Create an Open dialog; the default file name extension is ".my".
CFileDialog fileDlg(TRUE, _T("my"), _T("*.my"),
OFN_FILEMUSTEXIST | OFN_HIDEREADONLY, szFilters);
// 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();
SetWindowText(fileName);
}
}
对于“另存为”对话框,只需通过以下方式更改CFileDialog调用:
CFileDialog fileDlg(FALSE, _T("my"), _T("*.my"),
OFN_FILEMUSTEXIST | OFN_HIDEREADONLY, szFilters);
备注:
- 有些参数是可选的
- szFilters包含您需要的文件扩展名