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. A CFileDialog Question - selecting multiple files

A CFileDialog Question - selecting multiple files

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
5 Posts 3 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.
  • D Offline
    D Offline
    Dor
    wrote on last edited by
    #1

    I have created and displayed a file dialog to select multiple files. But when i select more then four files and hit enter or prell the ok button, the selection is erased and all that is left is the text in the entry box under the listbox. When trying to recover the files selected, the dialog box sends back nothing. can some one help me pleeeeese:confused:

    F PJ ArendsP 2 Replies Last reply
    0
    • D Dor

      I have created and displayed a file dialog to select multiple files. But when i select more then four files and hit enter or prell the ok button, the selection is erased and all that is left is the text in the entry box under the listbox. When trying to recover the files selected, the dialog box sends back nothing. can some one help me pleeeeese:confused:

      F Offline
      F Offline
      Fredrik Skog
      wrote on last edited by
      #2

      What flags do you pass to the constructor? I usually use OFN_HIDEREADONLY | OFN_ALLOWMULTISELECT Maybe you can post some code? Cheers,
      /Fredrik

      Do you Sonork? I do! 100.11430:PhatBoy

      1 Reply Last reply
      0
      • D Dor

        I have created and displayed a file dialog to select multiple files. But when i select more then four files and hit enter or prell the ok button, the selection is erased and all that is left is the text in the entry box under the listbox. When trying to recover the files selected, the dialog box sends back nothing. can some one help me pleeeeese:confused:

        PJ ArendsP Offline
        PJ ArendsP Offline
        PJ Arends
        wrote on last edited by
        #3

        You have to allocate your own buffer for the returned files. The default buffer is too small.

        TCHAR MyBuffer[1024];
        CFileDialog fdlg;
        fdlg.m_ofn.lpstrFile = MyBuffer;
        fdlg.m_ofn.nMaxFile = 1024;

        Look up OPENFILENAME in MSDN. --- Sonork 100.11743 Chicken Little It may be that your sole purpose in life is simply to serve as a warning to others.

        Within you lies the power for good; Use it!

        F 1 Reply Last reply
        0
        • PJ ArendsP PJ Arends

          You have to allocate your own buffer for the returned files. The default buffer is too small.

          TCHAR MyBuffer[1024];
          CFileDialog fdlg;
          fdlg.m_ofn.lpstrFile = MyBuffer;
          fdlg.m_ofn.nMaxFile = 1024;

          Look up OPENFILENAME in MSDN. --- Sonork 100.11743 Chicken Little It may be that your sole purpose in life is simply to serve as a warning to others.

          F Offline
          F Offline
          Fredrik Skog
          wrote on last edited by
          #4

          IMHO, it is easier to use the functions of CFileDialog to retrieve the files. Then you don't have to worry about buffer sizes. CString strFileName(""); POSITION pos; CStringList* strlistFileNames; CFileDialog FileDlg( true, // File Open dialog. "*", // Default file name extension. NULL, // No initial filename. OFN_HIDEREADONLY | OFN_ALLOWMULTISELECT, m_strNameMask + " (" + m_strSuffixMask + ")" + "|" + m_strSuffixMask + "|All Files (*.*)|*.*||" ); FileDlg.m_ofn.lpstrTitle = "Select files"; pos = FileDlg.GetStartPosition(); while (pos != NULL) { strlistFileNames->AddTail(FileDlg.GetNextPathName(pos)); } Cheers,
          /Fredrik

          Do you Sonork? I do! 100.11430:PhatBoy

          PJ ArendsP 1 Reply Last reply
          0
          • F Fredrik Skog

            IMHO, it is easier to use the functions of CFileDialog to retrieve the files. Then you don't have to worry about buffer sizes. CString strFileName(""); POSITION pos; CStringList* strlistFileNames; CFileDialog FileDlg( true, // File Open dialog. "*", // Default file name extension. NULL, // No initial filename. OFN_HIDEREADONLY | OFN_ALLOWMULTISELECT, m_strNameMask + " (" + m_strSuffixMask + ")" + "|" + m_strSuffixMask + "|All Files (*.*)|*.*||" ); FileDlg.m_ofn.lpstrTitle = "Select files"; pos = FileDlg.GetStartPosition(); while (pos != NULL) { strlistFileNames->AddTail(FileDlg.GetNextPathName(pos)); } Cheers,
            /Fredrik

            Do you Sonork? I do! 100.11430:PhatBoy

            PJ ArendsP Offline
            PJ ArendsP Offline
            PJ Arends
            wrote on last edited by
            #5

            From MSDN <quote> 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. </quote> --- Sonork 100.11743 Chicken Little It may be that your sole purpose in life is simply to serve as a warning to others.

            Within you lies the power for good; Use it!

            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