dlg
CFileDialog dlg(TRUE, _T(".txt"), NULL, OFN_ALLOWMULTISELECT | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
_T("文本文件(*.txt)|*.txt|所有文件(*.*)|*.*|| "), this) 各大侠请教 详细的什么意思
[解决办法]
CFileDialog::CFileDialog( BOOL bOpenFileDialog, LPCTSTR lpszDefExt = NULL, LPCTSTR lpszFileName = NULL, DWORD dwFlags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, LPCTSTR lpszFilter = NULL, CWnd* pParentWnd = NULL );
参数意义如下:
bOpenFileDialog 为TRUE则显示打开对话框,为FALSE则显示保存对话文件对话框。
lpszDefExt 指定默认的文件扩展名。
lpszFileName 指定默认的文件名。
dwFlags 指明一些特定风格。
lpszFilter 是最重要的一个参数,它指明可供选择的文件类型和相应的扩展名。参数格式如:
"Chart Files (*.xlc)|*.xlc|Worksheet Files (*.xls)|*.xls|Data Files (*.xlc;*.xls)|*.xlc; *.xls|All Files (*.*)|*.*||";文件类型说明和扩展名间用 | 分隔,同种类型文件的扩展名间可以用 ; 分割,每种文件类型间用 | 分隔,末尾用 || 指明。
pParentWnd 为父窗口指针。
[解决办法]
楼上讲的差不多了我再补充下:
lpszDefExt: 追加扩展名,不追加时为NULL
lpszFileName: 不设定名字时可以为NULL
dwFlags: 参照OPENFILENAME structure。这里的:
OFN_ALLOWMULTISELECT (//允许多选文件)
OFN_HIDEREADONLY (//隐藏只读文件)
OFN_OVERWRITEPROMPT(//文件名重复,保存时会提醒是否覆盖)
CFileDialog::CFileDialog
CFileDialog( BOOL bOpenFileDialog, LPCTSTR lpszDefExt = NULL, LPCTSTR lpszFileName = NULL, DWORD dwFlags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, LPCTSTR lpszFilter = NULL, CWnd* pParentWnd = NULL );
Parameters
bOpenFileDialog
Set to TRUE to construct a File Open dialog box or FALSE to construct a File Save As dialog box.
lpszDefExt
The default filename extension. If the user does not include an extension in the Filename edit box, the extension specified by lpszDefExt is automatically appended to the filename. If this parameter is NULL, no file extension is appended.
lpszFileName
The initial filename that appears in the filename edit box. If NULL, no filename initially appears.
dwFlags
A combination of one or more flags that allow you to customize the dialog box. For a description of these flags, see theOPENFILENAME structure in the Win32 SDK documentation. If you modify the m_ofn.Flags structure member, use a bitwise-OR operator in your changes to keep the default behavior intact.
lpszFilter
A series of string pairs that specify filters you can apply to the file. If you specify file filters, only selected files will appear in the Files list box. See the Remarks section for more information on how to work with file filters.
pParentWnd
A pointer to the file dialog-box object’s parent or owner window.