zoukankan      html  css  js  c++  java
  • CFileDialog “打开”与“另存为”对话框

    CFileDialog “打开”与“另存为”对话框

    void CMFCDialogDlg::OnBnClickedButtonOpen()
    {
        // 打开对话框
        //CFileDialog fileDlg(TRUE);
        //fileDlg.m_ofn.hwndOwner = this->GetSafeHwnd();//确定父窗口,若NULL,无父窗口
        //fileDlg.m_ofn.lpstrFilter = _T("Text Files(*.txt)*.txtAll Files(*.*)*.*");//过滤器
        //fileDlg.m_ofn.lpstrDefExt = _T("TXT");//默认扩展名
        //fileDlg.m_ofn.lpstrTitle = NULL;//若NULL,title是“打开”
        //或者
        //static TCHAR szFiler[] = _T("Text Files(*.txt)|*.txt|All Files(*.*)|*.*||");//注意:|前后不要写空格
        CFileDialog fileDlg(TRUE, _T("txt"), NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
            _T("Text Files(*.txt)|*.txt|All Files(*.*)|*.*||"), this);
        if (IDOK == fileDlg.DoModal())
        {
            CFile file;
            if(!file.Open(fileDlg.GetFileName(), CFile::modeRead))
                return;
            UINT nSize = file.GetLength();
            //ifile.SeekToBegin();
            //int n = ifile.SeekToEnd();
            char* buf = new char[nSize];
            file.Read(buf, nSize);
            //do something ...
            std::string s(buf, nSize);
            delete[] buf;
            file.Close();
        }
    }
    
    
    void CMFCDialogDlg::OnBnClickedButtonSave()
    {
        // "另存为"对话框
        CFileDialog fileDlg(FALSE);
        fileDlg.m_ofn.lpstrTitle = _T("我的文件保存对话框");//默认的Title是“另存为”
        fileDlg.m_ofn.lpstrFilter = _T("Text Files(*.txt)*.txtAll Files(*.*)*.*");
        fileDlg.m_ofn.lpstrDefExt = _T("txt");
        if (IDOK == fileDlg.DoModal())
        {
            CFile file(fileDlg.GetFileName(), CFile::modeCreate | CFile::modeWrite);
            file.Write("http://www.sunxin.org", strlen("http://www.sunxin.org"));
            file.Close();
        }
    }

    常记溪亭日暮,沉醉不知归路。兴尽晚回舟,误入藕花深处。争渡,争渡,惊起一滩鸥鹭。

    昨夜雨疏风骤,浓睡不消残酒。试问卷帘人,却道海棠依旧。知否?知否?应是绿肥红瘦。
  • 相关阅读:
    Android虚拟机 修改IMEI
    Android 真机调试缺少sqlite3
    DouBan FM API
    MySQL 常用命令[不断更新中]
    通过QRCode生成二维码与解码
    Ant 批量打包Android Umeng多渠道版本
    Centos服务器常用配置集合
    MTU详解
    openvswitch-with-conntrack_nat
    NAT介绍及NAT设备类型
  • 原文地址:https://www.cnblogs.com/htj10/p/12320816.html
Copyright © 2011-2022 走看看