这段代码的问题是?

program2100 2003-11-28 12:29:59
CFilDialog dlgOpenFile(...);//Allow multi select

if(IDOK == dlgOpenFile.DoModal())
{
...//Add filenames to a listbox
}
else
{
FormatMessage(...);//调用GetLastError()
MessageBox(...);
}
在FileDialog中选择少量文件就没有问题。一旦超过一定数量,
listbox中看不到任何item,单步调试证实表达式
IDOK == dlgOpenFile.DoModal()不成立,执行GetLastError()语句,
我用FormatMessage+MessageBox得到的信息是"The operation completed successfully"。这是怎么回事?
...全文
34 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
hahu 2003-11-28
  • 打赏
  • 举报
回复
CFileDialog在使用多选的时候要
先给他分配存放FileName的控件
看MSDN的介绍
To allow the user to select multiple files, set the OFN_ALLOWMULTISELECT flag before calling DoModal. You need to supply your own filename buffer to accommodate the returned list of multiple filenames. Do this by replacing m_ofn.lpstrFile with a pointer to a buffer you have allocated, after constructing the CFileDialog, but before calling DoModal. Additionally, you must set m_ofn.nMaxFile with the number of characters in the buffer pointed to by m_ofn.lpstrFile.
关键时OFN_ALLOWMULTISELECT
m_ofn.lpstrFile m_ofn.nMaxFile

dennis80 2003-11-28
  • 打赏
  • 举报
回复
UP,学习
tigerfox 2003-11-28
  • 打赏
  • 举报
回复
楼上已经说了。
bluebohe 2003-11-28
  • 打赏
  • 举报
回复
char str[2048];
str[0]=0;

dlgOpenFile.m_ofn.lpstrFile=str
dlgOpenFile.m_ofn.nMaxFile=2048;
if(IDOK == dlgOpenFile.DoModal())
{
...//Add filenames to a listbox
}
else
{
FormatMessage(...);//调用GetLastError()
MessageBox(...);
}
jerry 2003-11-28
  • 打赏
  • 举报
回复
多选时,你必需为文件名列表分配内存空间。
可能是你给多选分配的缓冲区不足。 加大一点。比如加大到1兆试试

15,978

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧