如果只选择一个文件,按确定则会---返回 IDCANCEL好奇怪啊!!!老革命遇到新问题

解决方案 »

  1.   

    CFileDialog dlg(TRUE,"txt",NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT|OFN_ALLOWMULTISELECT,
    "(*.text)|*.text|所有文件(*.*)|*.*|",AfxGetMainWnd() ); dlg.m_ofn.nMaxFile = 500; // 允许一次性选中文件的最多数
    CString str(" ",10000); 
    dlg.m_ofn.lpstrFile = str.GetBuffer(10000); 
    str.ReleaseBuffer(); 
      CString path;
    // int jn;
    if( ( dlg.DoModal()) == IDOK )
    {
              ...............
              }我这样写的
    没有问题
      

  2.   

    这个问题由于CFileDialog类的成员m_ofn.nMaxFile的长度未指定,或指定过小导致。
    用以下测试程序对于打开不同的文件,便可发现当打开文件2时发生的现象与你的情况一样。
    //文件1:"C:\a.txt"
    //文件2:"C:\aa.txt"
    CFileDialog dlgTest(
    TRUE,"txt",NULL,
    OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT|OFN_ALLOWMULTISELECT,
    "(*.txt)|*.txt|");dlgTest.m_ofn.nMaxFile = 10;//根据实现情况指定,此处指定仅供演示
    if( dlgTest.DoModal() == IDOK )
    {
    AfxMessageBox("");
    }
      

  3.   

    dlgTest.m_ofn.nMaxFile 我设置了 1024*1024
      

  4.   

    我的程序放到网上了,请各位大侠看看 
    http://www.betajin.com/alphasun/MultiFile.rar请注意URL的大小写
      

  5.   

    我下载了你的程序,修改BUF_LEN为 256*50,问题排除。#define BUF_LEN (256*50)
    char g_buf[BUF_LEN];void CMultiFileView::OnOpenMultiFiles() 
    {
    CFileDialog dlg(TRUE, NULL, NULL, OFN_ALLOWMULTISELECT,
    "all files(*.*)|*.*||",
    this); dlg.m_ofn.lpstrFile = g_buf;
    dlg.m_ofn.nMaxFile = BUF_LEN; CEdit &edit = GetEditCtrl(); edit.SetSel(-1,-1);
    if(dlg.DoModal()==IDOK)
    {
    POSITION pos = dlg.GetStartPosition();
    CString str;
    while(pos)
    {
    str = dlg.GetNextPathName(pos);
    edit.ReplaceSel(str);
    edit.ReplaceSel("\r\n");
    }
    }
    }
      

  6.   

    调查发现,dlg.m_ofn.nMaxFile的值小于256*255时,一切正常。
    当dlg.m_ofn.nMaxFile采用256*256以上的值时,选择单一文件,点击OK按钮,
    调试进入CFileDialog::DoModal()函数内部,发现GetOpenFileName函数返回值为0,
    最终致使DoModal()函数返回2(IDCANCEL)现象发生。DoModal()内部实现如下所示:
    int CFileDialog::DoModal()
    {
    //...
    if (m_bOpenFileDialog)
    nResult = ::GetOpenFileName(&m_ofn);
    //...
    }GetOpenFileName返回0的说明如下:
    Zero indicates that the user canceled or closed the Open dialog box or that an error occurred. 
    To get extended error information, call GetLastError. 
    GetOpenFileName sets only the ERROR_INVALID_PARAMETER and ERROR_OUTOFMEMORY errors.针对此问题,系统为何将此情况定义为ERROR_INVALID_PARAMETER,BUG?规定?我也无从得知,帮你UP。
      

  7.   

    唉呀。
    我的操作系统是 win2000。
    不知其他操作系统是否有此问题。
    不知这是不是操作系统的BUG。
      

  8.   

    MSDN中有过关于CFileDialogBUG的描述,请参见以下标题(问题号码),估计这是一个未完全修正的类似BUGFIX: Common File Dialog Multiple Selection File Limit Q179372