Chinaunix首页 | 论坛 | 博客
  • 博客访问: 103082
  • 博文数量: 29
  • 博客积分: 10
  • 博客等级: 民兵
  • 技术积分: 47
  • 用 户 组: 普通用户
  • 注册时间: 2012-12-13 16:46
文章分类
文章存档

2014年(20)

2013年(4)

2012年(5)

我的朋友

分类: WINDOWS

2014-10-31 10:24:42

原文地址:VC保存文件对话框 作者:luojiafeng1984


void CMailSearchDlg::ExportEmailList()
{    
    CString strExt = ".txt";                                // 扩展名
    CString strFilePath;
    CString strFilter;
    strFilter.Format("Text Files (*txt)|*txt|All Files (*.*)|*.*||");
    CFileDialog dlg(FALSE, NULL, "", NULL, strFilter);
    if (dlg.DoModal() == IDOK)
    {
        strFilePath = dlg.GetPathName();
        if (strFilePath.Find(strExt) == -1)
        {
            strFilePath += strExt;
        }
        if ( access(strFilePath, 0) == 0 )
        {
            CString strQuery;
            strQuery.Format("%s 已经存在,要替换它吗?", strFilePath);
            if ( IDNO == ::MessageBox(m_hWnd, strQuery, "文件覆盖询问", MB_ICONQUESTION | MB_YESNO) )
            {
                return;
            }
        }
        FILE *fp = fopen(strFilePath, "wt+");
        if ( fp != NULL )
        {
            for ( int i = 0; i < m_wndEmailList.GetItemCount(); i++ )
            {
                CString strMail = m_wndEmailList.GetItemText(i, 1);
                fputs(strMail, fp);
                fputs("\r\n", fp);
            }
            fclose(fp);
        }
    }
}

阅读(1267) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~