CAcUiFileDialog打开和关闭操作

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("程序生成成功"));
    }

打开文件的效果如图所示:

其中.CNC在文件文件(*.NC)下一条。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值