天气与日历 切换到窄版

 找回密码
 立即注册
中国膜结构网
十大进口膜材评选 十大国产膜材评选 十大膜结构设计评选 十大膜结构公司评选
查看: 60|回复: 0

CAcUiFileDialog打开和关闭操作

[复制链接]

该用户从未签到

主题

0

回帖

2912

积分

管理员

积分
2912
发表于 2024-6-22 09:46:18 | 显示全部楼层 |阅读模式
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("程序生成成功"));
    }

 

 

 

 

CAcUiFileDialog打开和关闭操作
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|中国膜结构网|中国膜结构协会|进口膜材|国产膜材|ETFE|PVDF|PTFE|设计|施工|安装|车棚|看台|污水池|中国膜结构网_中国空间膜结构协会

GMT+8, 2024-11-1 09:26 , Processed in 0.156811 second(s), 27 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表