Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Multiple selection in CFileDialog and CListBox

Multiple selection in CFileDialog and CListBox

Scheduled Pinned Locked Moved C / C++ / MFC
tutorial
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    julych
    wrote on last edited by
    #1

    I have enabled multiple file selection in an Open-a-File dialog. Please tell me how to obtain (a list of) all the selected files in this Open-a-file dialog and fill CListBox control with them.

    D 1 Reply Last reply
    0
    • J julych

      I have enabled multiple file selection in an Open-a-File dialog. Please tell me how to obtain (a list of) all the selected files in this Open-a-file dialog and fill CListBox control with them.

      D Offline
      D Offline
      Diddy
      wrote on last edited by
      #2

      Like this: CFileDialog aDlg(...); CListBox lb; if(aDlg.DoModal() == IDOK) { POSITION pos = aDlg.GetStartPosition(); while(pos != NULL) { CString file = aDlg.GetNextPathName(pos); lb.AddString(file); } }

      J 1 Reply Last reply
      0
      • D Diddy

        Like this: CFileDialog aDlg(...); CListBox lb; if(aDlg.DoModal() == IDOK) { POSITION pos = aDlg.GetStartPosition(); while(pos != NULL) { CString file = aDlg.GetNextPathName(pos); lb.AddString(file); } }

        J Offline
        J Offline
        julych
        wrote on last edited by
        #3

        Thanks a lot! It works great, but another problem is rising - if the selected files are too many (or the string in the "file name" edit control is too long) - nothing happens - i tried to change some of the members of the OPENFILENAME Structure, but with no result. Is it possible to make the "file name" edit control to accept longer strings and how?

        D 1 Reply Last reply
        0
        • J julych

          Thanks a lot! It works great, but another problem is rising - if the selected files are too many (or the string in the "file name" edit control is too long) - nothing happens - i tried to change some of the members of the OPENFILENAME Structure, but with no result. Is it possible to make the "file name" edit control to accept longer strings and how?

          D Offline
          D Offline
          Diddy
          wrote on last edited by
          #4

          No problem :) I'm not really sure what you are asking with the second part, so I'll try to answer three things you could mean :) 1. You get a problem when you have too many files seleced in the file dialog 2. You get a problem when the file name for one of them files selected is long 3. You get a problem when adding a large number of files, or a file with a long name, to the list box. 1. As for as I know there is no limited on the number of files you can select, I've never seen it anyway. The only problem you might get is because windows adds each file you select to the edit control, so if you select a lot you may overrun the edit control - is that what you mean? If so, see 2. 2. Hmmm... Well, the max length of a file name is MAX_PATH (255 chars) in Windows anyway, the edit control that accepts the file list should be able to take that easily, but with a lot of files it concevable you will overrun it. The only thing I can suggest is to use the "explorer style" file dialog (the one with the places bar down the side) this may be able to handle a large list of files better. Though you are now faced with another problem. Using the explorer dialog via MFC is tricky. You have to set define _WIN32_WINNT >= 0x0500 (which also means this will only work on 2k+) but thats not all there is to it because the setting this define adds some extra members to the OPENFILENAME struct which cause windows to display the explore style dialog rather than the new one. Unfotunatly, the size of OPENFILENAME is set with in MFC and short of recompiling MFC dlls, you are stuck with it. There are ways round it, search for OPENFILENAME on MSDN and look for 2000 Peridocal (called C++ Q AND A) buy Paul DiLascia. It's called "Windows 2000 File Dialog Revisited; Autocompletion and the ACTest Demo App" and it will show you how to use the new open dialog which might fix your problem. Of course if it doesn't, then.. err.. :) The other thing it might be is this: FIX: Common File Dialog Multiple Selection File Limit : Q179372 But this has aparently been fixed in a service pack. WHat version you running? 3. If this is your problem you are hitting a limit with the number of entrys a list box can handle, use a CListCtrl instead.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups