469,616 Members | 1,792 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,616 developers. It's quick & easy.

Opening multiple files in an MFC dialog application

79
I want to be able to select mutliple files from a standard File Open dialog box, and be able to open all those files simultaneously.

How can this be done? Is there a specific flag that you can use in the CFileDialog class constructor?

This is how I've been doing it, but just for one file:

CFileDialog FileDlg(TRUE, _T("*.txt"), NULL, 0, _T("Text Files (*.txt)|*.txt|" ));

Thanks
Jul 10 '07 #1
3 4050
weaknessforcats
9,208 Expert Mod 8TB
Read this. Especially, how to use OFN_ALLOWMULTISELECT.
Jul 11 '07 #2
ahammad
79
Thanks, I finally got it to work, but now there is another problem.

If I select a small number of files, it works. If I select a larger number of files (+5), it exits the loop as if I had clicked "cancel" in the dialog box.

Expand|Select|Wrap|Line Numbers
  1. CFileDialog cfileDlg( TRUE, _T("*.cpf"), NULL, OFN_ALLOWMULTISELECT, _T("CPF Files (*.cpf)|*.cpf|" ));
  2.  
  3.     CString csFileDlgTitle;
  4.  
  5.     cfileDlg.m_ofn.lpstrTitle = csFileDlgTitle;
  6.  
  7.     //int nRet = cfileDlg.DoModal( );
  8.     //ASSERT( ( nRet != IDOK ) || ( nRet != IDCANCEL ) );
  9.  
  10.     if (cfileDlg.DoModal() != IDOK) {
  11.         return;    //EXITS HERE IF I SELECT A LOT OF FILES, REGARDLESS OF WHAT I CLICK//
  12.     }
  13.  
  14.     POSITION pos ( cfileDlg.GetStartPosition() );
  15.  
  16.     while( pos )
  17.     {
  18.         CString csFileName(  cfileDlg.GetNextPathName( pos ) );
  19.  
  20.         FileOpenInput(csFileName);
The code that was commented out worked before, I took it out for other reasons.

I marked where the function terminates. That if statement is meant to be entered if the user clicks cancel in the File Open dialog box. What is the reason for this?

Thanks
Jul 11 '07 #3
weaknessforcats
9,208 Expert Mod 8TB
So if DoModal() does not return IDOK, then what does it return??

I would have expected code like:
Expand|Select|Wrap|Line Numbers
  1. if (cfileDlg.DoModal() == IDCANCEL)
  2. {
  3.         switch(CommDlgExtendedError())
  4.         {
  5.               case: CDERR_FINDRESFAILURE
  6.                        // etc...
  7.                       break;
  8. //etc...
  9. }
  10. //Then you get here on IDOK
  11.  
Jul 12 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by yanivoliver | last post: by
reply views Thread by vinX | last post: by
2 posts views Thread by Matt Hamilton | last post: by
5 posts views Thread by Stanav | last post: by
16 posts views Thread by iwdu15 | last post: by
10 posts views Thread by kimiraikkonen | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.