zoukankan      html  css  js  c++  java
  • C++语言 文件对话框的调用

    void CTestDlg::OnOpen() 
    {
        // TODO: Add your control notification handler code here
        //bOpenFileDialog(TRUE):'打开'对话框
        //lpszDefExt:扩展名
        //lpszFileName:文件名称
        //dwFlags:自定义文件对话框
        //lpszFilte:用于指定对话框过滤的文件类型(文件类型说明和扩展名间用"|"分隔,每种文件类型间用"|"分隔,末尾用"||"结束.)
        //pParentWnd:标识文件对话框的父窗口指针
        //CFileDialog dlg(TRUE, NULL, NULL, NULL, NULL, NULL);
        CFileDialog dlg(TRUE);
        CString strPath, strText = "";
        if(dlg.DoModal()==IDOK)
        {
            strPath = dlg.GetPathName();
            SetDlgItemText(IDC_STATIC1, strPath);
            CFile file(strPath, CFile::modeRead);
            char read[10000];
            file.Read(read, 10000);
            for(int i=0;i<file.GetLength();i++)
            {
                strText+=read[i];
            }
            file.Close();
            SetDlgItemText(IDC_EDIT1, strText);
        }
    }
    
    void CTestDlg::OnSave() 
    {
        // TODO: Add your control notification handler code here
        CFileDialog dlg(FALSE);
        CString strPath, strText="";
        char write[10000];
        if(dlg.DoModal()==IDOK)
        {
            strPath = dlg.GetPathName();
            if(strPath.Right(4)!=".TXT")
                strPath += ".TXT";
            SetDlgItemText(IDC_STATIC2, strPath);
            CFile file(_T(strPath), CFile::modeCreate|CFile::modeWrite);
            GetDlgItemText(IDC_EDIT1, strText);
            strcpy(write, strText);
            file.Write(write,strText.GetLength());
            file.Close();
        }
        
    }
  • 相关阅读:
    Java EE 在网页输出九九乘法表、三角形、菱形
    Java EE 在网页输出九九乘法表
    格式化时间(SimpleDateFormat)
    Java代码规范性
    Scanner
    数据库怎么删除相同的内容
    连接池 ----单例模式
    多态和接口
    第一个JAVA应用
    继承
  • 原文地址:https://www.cnblogs.com/pythonschool/p/2773648.html
Copyright © 2011-2022 走看看