程序变一变,过程很麻烦!!!请高手支招!

xking_xking 2009-06-29 11:15:02
请问vc++在单文档模板下,怎么编程实现用文件对话框或者列表控件,一次打开多个文件,并将每个文件的内容读倒数组中。
我开始使用文件对话框做的,只能读出一个文件现在想改成能读多个文件的,msdn里的说明每看明白,请高手指点!!
我开始大体上是这样做的:
void CTestView::OnRead()
{
CFileDialog file(TRUE);
if(file.DoModal()==IDOK)
{
CString str;
str=file.GetFileName();
char buffer[80]=m_file.ReadFile(str);/////////////读文件函数
}
}
要读多个文件的话,数组是不是还要扩大,或者变成二维的?
...全文
44 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
xking_xking 2009-06-30
  • 打赏
  • 举报
回复
谢谢啊!我的msdn没有下面的例子。Do this by replacing m_ofn.lpstrFile with a pointer to a buffer you have allocated, after constructing the CFileDialog, but before calling DoModal.这句没看明白。怎么实现指针更替,还有从数组里顺序读出文件名啊?请指教!
zhyp011 2009-06-30
  • 打赏
  • 举报
回复
CFileDlg dlg( TRUE,_T("TXT"),_T("*.TXT"),

OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT|OFN_ALLOWMULTISELECT,

_T("文本文件 (*.txt)|*.txt所有文件 (*.*)|*.*|"));

if(dlg.DoModal()!=IDOK) return FALSE;

while (pos != NULL)

{

CString strPath = dlg.GetNextPathName(pos);

if (strPath.Find(":\\\\") == 1 && strPath.GetLength() > 4)

{

CString temp;

temp = strPath.Left(3);

temp += strPath.Mid(4);

strPath = temp;

}
supconsupcon 2009-06-30
  • 打赏
  • 举报
回复
看下面的代码:
CFileDialog dlg( TRUE, NULL, NULL, OFN_ALLOWMULTISELECT, NULL, NULL );
DWORD MAXFILE = 100000; //2562 is the max by default
dlg.m_ofn.nMaxFile = MAXFILE;
char* pc = new char[MAXFILE];
dlg.m_ofn.lpstrFile = pc; // 此处进行替换
dlg.m_ofn.lpstrFile[0] = NULL; // 此处是清零操作
clever101 2009-06-29
  • 打赏
  • 举报
回复

你说的跟单文档程序和对话框程序没啥关系,你的功能在单文档程序和对话框程序都能实现,其实质在于让允许
文件对话框一次选择打开多个文件,参开下面的文档:


According to the CFileDialog overview:

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.

for example,

CFileDialog dlg( TRUE, NULL, NULL, OFN_ALLOWMULTISELECT, NULL, NULL );
DWORD MAXFILE = 100000; //2562 is the max by default
dlg.m_ofn.nMaxFile = MAXFILE;
char* pc = new char[MAXFILE];
dlg.m_ofn.lpstrFile = pc;
dlg.m_ofn.lpstrFile[0] = NULL;

see
http://support.microsoft.com/default.aspx?scid=KB;en-us;Q179372

16,550

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Creator Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

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