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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. OpenFileName Multiselect problem

OpenFileName Multiselect problem

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
4 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.
  • C Offline
    C Offline
    Chandrasekharan P
    wrote on last edited by
    #1

    I have a problem with this code

    CString l\_FilePath;
    CFileDialog m\_ldFile(TRUE,"txt","\*.txt",OFN\_ALLOWMULTISELECT | OFN\_EXPLORER);
    m\_ldFile.m\_ofn.lpstrFilter = "\*.txt";
    
    
    	
    if (m\_ldFile.DoModal() == IDOK)
    {
    	POSITION temp = m\_ldFile.GetStartPosition();
    	while(temp)
    	{
    		l\_FilePath = m\_ldFile.GetNextPathName(temp);
    		m\_lstFiles.AddString(l\_FilePath);		
    	}
    }
    

    Now the problem. i have 8 files in a folder. when i select all the files and try to put the files in a listbox nothing is displaying. but when i am selecting only 7 files then the files are getting displayed. why is that so?

    M L 2 Replies Last reply
    0
    • C Chandrasekharan P

      I have a problem with this code

      CString l\_FilePath;
      CFileDialog m\_ldFile(TRUE,"txt","\*.txt",OFN\_ALLOWMULTISELECT | OFN\_EXPLORER);
      m\_ldFile.m\_ofn.lpstrFilter = "\*.txt";
      
      
      	
      if (m\_ldFile.DoModal() == IDOK)
      {
      	POSITION temp = m\_ldFile.GetStartPosition();
      	while(temp)
      	{
      		l\_FilePath = m\_ldFile.GetNextPathName(temp);
      		m\_lstFiles.AddString(l\_FilePath);		
      	}
      }
      

      Now the problem. i have 8 files in a folder. when i select all the files and try to put the files in a listbox nothing is displaying. but when i am selecting only 7 files then the files are getting displayed. why is that so?

      M Offline
      M Offline
      Michael Schubert
      wrote on last edited by
      #2

      The buffer to hold the file names may not be big enough. Try this:

      char szBuffer[64000] = "";
      m_ldFile.m_ofn.lpstrFile = szBuffer;
      m_ldFile.m_ofn.nMaxFile = sizeof(szBuffer);

      Edit: See also here: http://msdn.microsoft.com/en-us/library/dk77e5e7.aspx[^]

      1 Reply Last reply
      0
      • C Chandrasekharan P

        I have a problem with this code

        CString l\_FilePath;
        CFileDialog m\_ldFile(TRUE,"txt","\*.txt",OFN\_ALLOWMULTISELECT | OFN\_EXPLORER);
        m\_ldFile.m\_ofn.lpstrFilter = "\*.txt";
        
        
        	
        if (m\_ldFile.DoModal() == IDOK)
        {
        	POSITION temp = m\_ldFile.GetStartPosition();
        	while(temp)
        	{
        		l\_FilePath = m\_ldFile.GetNextPathName(temp);
        		m\_lstFiles.AddString(l\_FilePath);		
        	}
        }
        

        Now the problem. i have 8 files in a folder. when i select all the files and try to put the files in a listbox nothing is displaying. but when i am selecting only 7 files then the files are getting displayed. why is that so?

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        Hi Chandru, Michael Schubert gave you a working solution but it may also fail if the buffer is too small. I like the solution offered by PJ Arends where you dont have to worry about the size of the buffer. Multiple Selection in a File Dialog[^] Its a really good technique. Best Wishes, -David Delaune

        M 1 Reply Last reply
        0
        • L Lost User

          Hi Chandru, Michael Schubert gave you a working solution but it may also fail if the buffer is too small. I like the solution offered by PJ Arends where you dont have to worry about the size of the buffer. Multiple Selection in a File Dialog[^] Its a really good technique. Best Wishes, -David Delaune

          M Offline
          M Offline
          Michael Schubert
          wrote on last edited by
          #4

          Much better solution indeed. My example was really just a suggestion to test whether it's a problem with the buffer being too small.

          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