在vc ++中创建另存为对话框 [英] Creating Save As dialog box in vc++
本文介绍了在vc ++中创建另存为对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在vc ++(MFC)中创建另存为"对话框?
How to create Save As dialog box in vc++(MFC)?
推荐答案
您可以使用类似这样的内容;
You could use something like this;
int GetFileName(HWND hwndOwner,char *filename)
{ OPENFILENAME ofn = {0};
ofn.lStructSize = sizeof(ofn);
ofn.Flags = OFN_EXPLORER | OFN_PATHMUSTEXIST;
ofn.hInstance = GetModuleHandle(0);
ofn.hwndOwner = hwndOwner;
ofn.nMaxFile = MAX_PATH;
ofn.lpstrFile = filename;
ofn.nFilterIndex = 1;
ofn.lpstrFilter = "Text file\0*.txt\0Any file\0*.*\0";
ofn.lpstrDefExt = "txt";
return GetSaveFileName(&ofn);
}
hwndOwner
是拥有SaveAs对话框的窗口的句柄,而filename
是长度为MAX_PATH的字符数组.
将lpstrFilter
和lpstrDefExt
变量更改为适合您的应用程序的文件类型.
hwndOwner
is a handle to the window that owns the SaveAs dialog and filename
is a character array with length MAX_PATH.
Change the lpstrFilter
and lpstrDefExt
variables to an appropriate file type for your application.
Thaddeus Jones答案是正确的.您还可以使用CFileDialog
类:
保存:
Thaddeus Jones answer is correct. You can also use theCFileDialog
class:
For saving:
CFileDialog dlg(FALSE, defaultExtension, NULL, OFN_OVERWRITEPROMPT, "All files|*.*||");
if (dlg.DoModal() != IDOK)
{
//the user didn''t click OK
return;
}
CString theFileName = dlg.GetPathName();
//save the file...
加载:
For loading:
CFileDialog dlg(TRUE, defaultExtension, NULL, OFN_HIDEREADONLY, "All files|*.*||");
if (dlg.DoModal() != IDOK)
{
//the user didn''t click OK
return;
}
CString theFileName = dlg.GetPathName();
//load the file...
这篇关于在vc ++中创建另存为对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文