调查发现,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。
"(*.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时发生的现象与你的情况一样。
//文件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("");
}
http://www.betajin.com/alphasun/MultiFile.rar请注意URL的大小写
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");
}
}
}
当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。
我的操作系统是 win2000。
不知其他操作系统是否有此问题。
不知这是不是操作系统的BUG。