By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,345 Members | 1,221 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,345 IT Pros & Developers. It's quick & easy.

Opening multiple files in an MFC dialog application

P: 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
Share this Question
Share on Google+
3 Replies

weaknessforcats
Expert Mod 5K+
P: 9,197
Read this. Especially, how to use OFN_ALLOWMULTISELECT.
Jul 11 '07 #2

P: 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
Expert Mod 5K+
P: 9,197
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.