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. Winprog OPENFILENAME

Winprog OPENFILENAME

Scheduled Pinned Locked Moved C / C++ / MFC
helpjsonquestion
2 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.
  • H Offline
    H Offline
    henry128
    wrote on last edited by
    #1

    Need help please. Sorry for long and tedious introduction. In Win32 API the OpenFileDialog runs by initializing the OPENFILENAME struct. (quote msdn) a buffer provided in the ofn.lpstrFile member holds all the file info including path. The ofn.lpstrFileTitle holds the name of the file and ofn.MaxFile member points to the offset in the string contained in lpstrFile where the filename is located. If ofn.dwFlags is provided with the OFN_ALLOWMULTISELECT flag ,one is able to select multiple files at a time ,which all are contained-separated by '\0'- in the lpstrFile buffer. So this would look someting like "C:\programs\myapp\0file1.txt\0file2.txt\0" msdn states that if the multiselect-flag is NOT set,than the system takes the path info from the lpstrFile buffer. However,this seems not to be the case when the multiselect flag is set. It seems that in multi-mode directory information is no longer preserved. Sadly msdn doesn't touch this subject, does anyone know if ,and how the path info in case of multiselect is stored? For processing more selected files, I read them out of the buffer one at a time and strcat them to the path,yielding a usable file-identifier. Problem however is that if I select files from directories that are further from the root,and with many characters in their name, these files seem to be invalid as the system doesn't process them any more. As this smells of a buffer undersize,I tried enlarging sizes of various buffers and intermediate var's but however, with no success up to now. Maybe someone has a tip? I.m currently ona Win2k system thanx in advance

    D 1 Reply Last reply
    0
    • H henry128

      Need help please. Sorry for long and tedious introduction. In Win32 API the OpenFileDialog runs by initializing the OPENFILENAME struct. (quote msdn) a buffer provided in the ofn.lpstrFile member holds all the file info including path. The ofn.lpstrFileTitle holds the name of the file and ofn.MaxFile member points to the offset in the string contained in lpstrFile where the filename is located. If ofn.dwFlags is provided with the OFN_ALLOWMULTISELECT flag ,one is able to select multiple files at a time ,which all are contained-separated by '\0'- in the lpstrFile buffer. So this would look someting like "C:\programs\myapp\0file1.txt\0file2.txt\0" msdn states that if the multiselect-flag is NOT set,than the system takes the path info from the lpstrFile buffer. However,this seems not to be the case when the multiselect flag is set. It seems that in multi-mode directory information is no longer preserved. Sadly msdn doesn't touch this subject, does anyone know if ,and how the path info in case of multiselect is stored? For processing more selected files, I read them out of the buffer one at a time and strcat them to the path,yielding a usable file-identifier. Problem however is that if I select files from directories that are further from the root,and with many characters in their name, these files seem to be invalid as the system doesn't process them any more. As this smells of a buffer undersize,I tried enlarging sizes of various buffers and intermediate var's but however, with no success up to now. Maybe someone has a tip? I.m currently ona Win2k system thanx in advance

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      henry128 wrote: However,this seems not to be the case when the multiselect flag is set. It seems that in multi-mode directory information is no longer preserved. Sadly msdn doesn't touch this subject, does anyone know if ,and how the path info in case of multiselect is stored? This works for me:

      OPENFILENAME ofn = {0};
      char szBuffer[4096] = {0},
      szPath[MAX_PATH];

      ofn.lStructSize = sizeof(OPENFILENAME);
      ofn.lpstrFilter = "All Files (*.*)\0*.*\0";
      ofn.lpstrFile = szBuffer;
      ofn.nMaxFile = sizeof(szBuffer);
      ofn.Flags = OFN_ALLOWMULTISELECT | OFN_EXPLORER;

      if (GetOpenFileName(&ofn) != FALSE)
      {
      lstrcpy(szPath, ofn.lpstrFile);
      ofn.lpstrFile += ofn.nFileOffset;

      while (\*(ofn.lpstrFile) != '\\0')
      {
          TRACE("%s\\\\%s\\n", szPath, ofn.lpstrFile);
          ofn.lpstrFile += lstrlen(ofn.lpstrFile) + 1;
      }
      

      }

      However, without a code snippet showing what you have (tried), it's hard to suggest a solution.


      "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

      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