zoukankan      html  css  js  c++  java
  • 选择目录对话框和选择文件对话框

    在MFC编程中经常会需要用到选择目录和选择文件的界面,以下总结一下本人常用的这两种对话框的生成方法:

    选择目录对话框

    //选择目录按钮
    void CDcPackerDlg::OnBnClickedDecgen()    
    {
        char szPath[MAX_PATH];     //存放选择的目录路径 
        CString str;
    
        ZeroMemory(szPath, sizeof(szPath));   
    
        BROWSEINFO bi;   
        bi.hwndOwner = m_hWnd;   
        bi.pidlRoot = NULL;   
        bi.pszDisplayName = szPath;   
        bi.lpszTitle = "请选择需要打包的目录:";   
        bi.ulFlags = 0;   
        bi.lpfn = NULL;   
        bi.lParam = 0;   
        bi.iImage = 0;   
        //弹出选择目录对话框
        LPITEMIDLIST lp = SHBrowseForFolder(&bi);   
    
        if(lp && SHGetPathFromIDList(lp, szPath))   
        {
            str.Format("选择的目录为 %s",  szPath);
            AfxMessageBox(str); 
    
           
        }
        else   
            AfxMessageBox("无效的目录,请重新选择");   
    }


    选择文件对话框

    CString CDcPackerDlg::BootOpenDialog()   //返回选择的文件名称
    {
        CString strFile = _T("");
    
        CFileDialog    dlgFile(TRUE, NULL, NULL, OFN_HIDEREADONLY, _T("Describe Files (*.cfg)|*.cfg|All Files (*.*)|*.*||"), NULL);
    
        if (dlgFile.DoModal())
        {
            strFile = dlgFile.GetPathName();
        }
    
        return strFile;
    }


    //加载文件按钮
    void CDcPackerDlg::OnBnClickedSelectdec()
    {
        // TODO: Add your control notification handler code here
        m_strDescPath = "";        //类的成员变量
    
        //"打开文件"对话框,选择文件,返回其路径
        m_strDescPath = BootOpenDialog();   
    }
  • 相关阅读:
    linux文件锁flock【转】
    无尽的悲伤
    go的临时对象池--sync.Pool
    golang 小知识-持续更新中
    【转】Go Channels
    Golang文件名命名规则
    Parquet存储格式
    预装的Office2016,文件图标表显示以及新建失败问题解决 方法
    Gamma编码及Delta编码概述
    java web开发环境配置系列(二)安装tomcat
  • 原文地址:https://www.cnblogs.com/duanqiao/p/3517055.html
Copyright © 2011-2022 走看看