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

A CFileDialog Question

Scheduled Pinned Locked Moved C / C++ / MFC
questionhardware
9 Posts 5 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
    Jethro63
    wrote on last edited by
    #1

    Greetings: I need to launch a CFileDialog box but I need to implement special file name filtering. That is, I might filter with a file name extension like "TXT", however, I need to filter even further by excluding files that have certain sub-strings embedded in their names. The wild card method is not going to work here because I need to exclude file names that have certain characteristics, not include them. This requirement has been thrust upon me and I simply have to find a solution. I can't see anything in the documentation that says you can do this. Any suggestions? Thank you, Mark

    D 1 Reply Last reply
    0
    • J Jethro63

      Greetings: I need to launch a CFileDialog box but I need to implement special file name filtering. That is, I might filter with a file name extension like "TXT", however, I need to filter even further by excluding files that have certain sub-strings embedded in their names. The wild card method is not going to work here because I need to exclude file names that have certain characteristics, not include them. This requirement has been thrust upon me and I simply have to find a solution. I can't see anything in the documentation that says you can do this. Any suggestions? Thank you, Mark

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

      Jethro63 wrote:

      This requirement...

      Does it also include using CFileDialog?


      "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

      "Judge not by the eye but by the heart." - Native American Proverb

      J 1 Reply Last reply
      0
      • D David Crow

        Jethro63 wrote:

        This requirement...

        Does it also include using CFileDialog?


        "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

        "Judge not by the eye but by the heart." - Native American Proverb

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

        Hi David: No, not necessarily. I am becoming resigned to the possibility that I'll just have to construct my own selection dialog. No big deal, just another little thing on the great-big pile. But I was expecting (or hoping) that under the hood of CFileDialog, there might be a mechanism, an optional callback function perhaps, where each time the dialog was about to add another entry to the list box embedded in the dialog, the callback would first be called and you could use this callback to do any manner of screening that you need and say "yes" or "no" to adding the file. No such luck, apparently. So, I'm open to suggestions but I need to get this done. It is a minor requirement in the grand scheme of things but I have already spent a lot of time trying to come up with a solution. Thanks, Mark

        P W 2 Replies Last reply
        0
        • J Jethro63

          Hi David: No, not necessarily. I am becoming resigned to the possibility that I'll just have to construct my own selection dialog. No big deal, just another little thing on the great-big pile. But I was expecting (or hoping) that under the hood of CFileDialog, there might be a mechanism, an optional callback function perhaps, where each time the dialog was about to add another entry to the list box embedded in the dialog, the callback would first be called and you could use this callback to do any manner of screening that you need and say "yes" or "no" to adding the file. No such luck, apparently. So, I'm open to suggestions but I need to get this done. It is a minor requirement in the grand scheme of things but I have already spent a lot of time trying to come up with a solution. Thanks, Mark

          P Offline
          P Offline
          PJ Arends
          wrote on last edited by
          #4

          Look up CDN_INCLUDEITEM in MSDN.


          You may be right
          I may be crazy
          -- Billy Joel --

          Within you lies the power for good, use it!!!

          J 1 Reply Last reply
          0
          • P PJ Arends

            Look up CDN_INCLUDEITEM in MSDN.


            You may be right
            I may be crazy
            -- Billy Joel --

            Within you lies the power for good, use it!!!

            J Offline
            J Offline
            Jethro63
            wrote on last edited by
            #5

            That is exactly what I was looking for! Thanks! Mark

            1 Reply Last reply
            0
            • J Jethro63

              Hi David: No, not necessarily. I am becoming resigned to the possibility that I'll just have to construct my own selection dialog. No big deal, just another little thing on the great-big pile. But I was expecting (or hoping) that under the hood of CFileDialog, there might be a mechanism, an optional callback function perhaps, where each time the dialog was about to add another entry to the list box embedded in the dialog, the callback would first be called and you could use this callback to do any manner of screening that you need and say "yes" or "no" to adding the file. No such luck, apparently. So, I'm open to suggestions but I need to get this done. It is a minor requirement in the grand scheme of things but I have already spent a lot of time trying to come up with a solution. Thanks, Mark

              W Offline
              W Offline
              Waldermort
              wrote on last edited by
              #6

              Creating your own dialog would be the easier choice. You could also allow the CFileDialog to do it's job, then before showing it to the user, iterate through it's list box performing your own additional scan of the files. All you need to do is find the window handle to it's listbox, then use the normal api functions to remove items.

              J 1 Reply Last reply
              0
              • W Waldermort

                Creating your own dialog would be the easier choice. You could also allow the CFileDialog to do it's job, then before showing it to the user, iterate through it's list box performing your own additional scan of the files. All you need to do is find the window handle to it's listbox, then use the normal api functions to remove items.

                J Offline
                J Offline
                Jethro63
                wrote on last edited by
                #7

                Does this dialog expose the handle to its list box? Is there not a risk of screwing things up? For example, maybe I can remove the entries from the list box but what if there is an under-lying collection (like, say, CStringArray) that contains the entries and these entries are not removed? The list box would become un-synchronized with the internal list... Thank you, Mark

                H 1 Reply Last reply
                0
                • J Jethro63

                  Does this dialog expose the handle to its list box? Is there not a risk of screwing things up? For example, maybe I can remove the entries from the list box but what if there is an under-lying collection (like, say, CStringArray) that contains the entries and these entries are not removed? The list box would become un-synchronized with the internal list... Thank you, Mark

                  H Offline
                  H Offline
                  Haroon Sarwar
                  wrote on last edited by
                  #8

                  did CDN_INCLUDEITEM work for you? As I recall it does not quite work as you would first expect... I needed to do exactly what you did, the only solution I could find was provided by Paul DiLascia: http://msdn.microsoft.com/msdnmag/issues/03/10/CQA/ There doesn't seem to be any under-lying collection, as this solution worked fine for me...the only problem is in this solution is you're deleting unwanted files from the list after they have been added rather than just excluding them in the first place...

                  W 1 Reply Last reply
                  0
                  • H Haroon Sarwar

                    did CDN_INCLUDEITEM work for you? As I recall it does not quite work as you would first expect... I needed to do exactly what you did, the only solution I could find was provided by Paul DiLascia: http://msdn.microsoft.com/msdnmag/issues/03/10/CQA/ There doesn't seem to be any under-lying collection, as this solution worked fine for me...the only problem is in this solution is you're deleting unwanted files from the list after they have been added rather than just excluding them in the first place...

                    W Offline
                    W Offline
                    Waldermort
                    wrote on last edited by
                    #9

                    Another similar option would be to populate the dialogs list with an obviously stupid file extension, then add the items yourself.

                    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