471,863 Members | 1,117 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,863 software developers and data experts.

Opening multiple files in an MFC dialog application

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|" ));

Jul 10 '07 #1
3 4291
9,208 Expert Mod 8TB
Read this. Especially, how to use OFN_ALLOWMULTISELECT.
Jul 11 '07 #2
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|" ));
  3.     CString csFileDlgTitle;
  5.     cfileDlg.m_ofn.lpstrTitle = csFileDlgTitle;
  7.     //int nRet = cfileDlg.DoModal( );
  8.     //ASSERT( ( nRet != IDOK ) || ( nRet != IDCANCEL ) );
  10.     if (cfileDlg.DoModal() != IDOK) {
  12.     }
  14.     POSITION pos ( cfileDlg.GetStartPosition() );
  16.     while( pos )
  17.     {
  18.         CString csFileName(  cfileDlg.GetNextPathName( pos ) );
  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?

Jul 11 '07 #3
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
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 NeoPa | last post: by
reply views Thread by YellowAndGreen | last post: by
reply views Thread by aboka | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.