zoukankan      html  css  js  c++  java
  • CFileDialog打开多个文件失败 返回错误 FNERR_BUFFERTOOSMALL

    需要使用CFileDialog,产生一个文件多选的对话框。但是默认的lpstrFile缓冲区只有200多,当打开比较多的文件时容易超过缓冲区返回错误:FNERR_BUFFERTOOSMALL 由CommDlgExtendedError()返回。

    查看MSDN解释:

    ValueMeaning
    FNERR_BUFFERTOOSMALL The buffer pointed to by the lpstrFile member of the OPENFILENAME structure is too small for the filename specified by the user. The first two bytes of the lpstrFile buffer contain an integer value specifying the size, in bytes (ANSI version) or 16-bit characters (Unicode version), required to receive the full name.


    那就手动将缓冲区设置大一点即可。缓冲区的上限是2562。看下面示例:

    char* lpFile;   
    CFileDialog FileDlg(TRUE,NULL,NULL,NULL,   
            
    "Media Files (*.avi;*.mkv)|*.avi;*.mkv|All Files (*.*)|*.*||");   
      
    FileDlg.m_ofn.nMaxFile
    =2562;      
    lpFile
    =new char[2562];      
    FileDlg.m_ofn.lpstrFile
    =lpFile;      
    FileDlg.m_ofn.lpstrFile[
    0]=NULL;   
      
    FileDlg.m_ofn.Flags 
    |= OFN_ALLOWMULTISELECT | OFN_EXPLORER;  //设置可多选文件标志   
    FileDlg.m_ofn.lStructSize=88;  //设置EXPLORER风格   
      
    if (FileDlg.DoModal()==IDOK)   
       {   
            CString strFilePath
    ="";   
            POSITION p
    =FileDlg.GetStartPosition();   
            
    while (p)   
            {   
                 strFilePath
    =FileDlg.GetNextPathName(p);    
                 
    //处理每个文件路径   
             }   
       }
       delete[] lpFile;

      

    还可以参考codeproject上的实例代码:

    链接:http://www.codeproject.com/KB/dialog/pja_multiselect.aspx

  • 相关阅读:
    K均值算法
    4.K均值算法应用
    js实现点击不同按钮切换内容
    vue框架中的日期组件转换为yyymmdd格式
    sessionStorage和localStorage的使用方法
    vue中使用axios
    js中的原型对象链
    web端常见测试点
    软件测试手工测试
    前端面试题vue部分
  • 原文地址:https://www.cnblogs.com/ciey/p/1540550.html
Copyright © 2011-2022 走看看