|
CFileDialog打开文件和关闭文件很简单。重点注意文件名过滤器的使用格式,MSDN官方对CFileDialog的定义如下格式:
explicit CFileDialog(
BOOL bOpenFileDialog,
LPCTSTR lpszDefExt = NULL,
LPCTSTR lpszFileName = NULL,
DWORD dwFlags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
LPCTSTR lpszFilter = NULL,
CWnd* pParentWnd = NULL,
DWORD dwSize = 0,
BOOL bVistaStyle = TRUE
);
其他参数参考MSDN文档,现将文件过滤器部分的定义列出。
[in] lpszFilter
A series of string pairs that specify filters you can apply to the file. If you specify file filters, only files that match filter criteria will appear in the Files list. See the Remarks section for more information about how to work with file filters.
The lpszFilter parameter is used to determine the type of file name a file must have to be displayed in the file list. The first string in the string pair describes the filter; the second string indicates the file name extension to use. Multiple extensions may be specified by using a semicolon (the ';' character) as the delimiter. The string ends with two '|' characters, followed by a NULL character. You can also use a CString object for this parameter.
For example, Microsoft Excel allows users to open files that have extensions .xlc (chart) or .xls (worksheet), among others. The filter for Excel could be written as:
static TCHAR BASED_CODE szFilter[] = _T("Chart Files (*.xlc)|*.xlc|")
_T("Worksheet Files (*.xls)|*.xls|Data Files (*.xlc;*.xls)|")
_T("*.xlc; *.xls|All Files (*.*)|*.*||");
按照此说明编写如下程序:
TCHAR szFilter[] = TEXT("文本文件(*.NC)|*.NC|文本文件(*.CNC)|*.CNC|所有文件(*.*)|*.*||");
CAcUiFileDialog fileDlg(FALSE, TEXT("NC"), NULL, 0, szFilter, NULL);
CString filePath = TEXT("D:\\");
if(fileDlg.DoModal() == IDOK)
{
filePath = fileDlg.GetPathName();
CFile file;
file.Open(filePath,CFile::modeCreate | CFile::modeWrite);
file.Write(GCodeBuf,strlen(GCodeBuf));
file.Close();
acutPrintf(TEXT("\nProgram Generate Success"));
AfxMessageBox(TEXT("程序生成成功"));
}
|
|