Solved

CFileDialog multiple selection including folders

Posted on 1998-08-18
9
570 Views
Last Modified: 2013-11-20
How can one get the result of selecting multiple files and directories/folders in a CFileDialog?

RJV
0
Comment
Question by:RJV
  • 4
  • 4
9 Comments
 
LVL 9

Expert Comment

by:Priyesh
ID: 1320947
RJV,

CFileDialof fileDialog ;
fileDialog.DoModal() ;
            POSITION position;

            position = fileDialog.GetStartPosition();
            while (position != NULL)
            {
                               //Get items using GetNextPathName of FileDialog..                        
            }

This is quite sufficient i suppose..
        Regards..Priyesh.
0
 

Author Comment

by:RJV
ID: 1320948
Priyesh,

Unfortunately it isn't sufficient. Before posting my question I had done exactly that. I you run through it you'll find that it returns all of the files that were selected. Any directories or folders selected are not returned at all; only the files.

That's why I posted the question.

RJV

0
 
LVL 1

Accepted Solution

by:
rlarner earned 100 total points
ID: 1320949
As far as I know it is impossible to truely 'select' directories (aka folders) in the open _file_ dialog box.  You can have directories highlighted, but the dialog box does not consider them selected, since it is the open file dialog box and therefore cannot 'open' directories.  This has long been a beef of mine with this control.  I do believe that you may be able to find 3rd party controls that will allow you to select both, or if you override the CFileDialog class you may be able to get it working yourself.  The MFC Programmer's Sourcebook has some details on overloading a CFileDialog to only allow selecting directories -- look in 'http://www.codeguru.com/dialog/index.shtml', under the "Dialog for selecting folders" heading.
0
 

Author Comment

by:RJV
ID: 1320950
I've visited codeguru and the solutions posted there are indeed restricted only to picking the directory. In fact, I also already had subclassed CFileDialog. Thus I tried accessing its CListCtrl. If I can access the text in the list control I should be clear. Unfortunately attempts at that led junk when getting the text, though apparently I was able to get the right index to the item. I say apparently as from that I should have been able to get the right text, an not a mess.

If you can figure that part out (i.e. getting the right text) I should be clear, in which case I'd also post the outcome here.

RJV

0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 1

Expert Comment

by:rlarner
ID: 1320951
Hmm...  When did you try to access the CListCtrl?  It could easily be that the CListCrl ceases to exist during the return.  If you take a look at the source in http://www.codeguru.com/dialog/folder_dialog_source.zip,
you'll see that they overload the WindowProcNew handler to get the information they want out of the common control.  I believe this is because the common controls handle this message, fill the appropriate return structure, and then delete their dialogs.  Try  grabbing the list control in the same way that they did.  Something like this:


LRESULT CALLBACK WindowProcNew(HWND hwnd,UINT message, WPARAM wParam, LPARAM lParam)
{
      
      if (message ==  WM_COMMAND)
            if (HIWORD(wParam) == BN_CLICKED)
                  if (LOWORD(wParam) == IDOK)
                  {
                        if (CFileDialog* pDlg = (CFileDialog*)CWnd::FromHandle(hwnd))
                        {
                              TCHAR path[MAX_PATH];
                              GetCurrentDirectory(MAX_PATH, path);
                              CListCtrl* pListCtrl = (CListCtrl*)pDlg->GetDlgItem(lst1);
                              // OK, now you loop through the list control's items...
                              TODO: Put loop here
                              // Now, call the standard handler.
                              pDlg->EndDialog(IDOK);
                              return NULL;
                        }
                  }
      return CallWindowProc(CFolderDialog::m_wndProc, hwnd, message, wParam, lParam);
}

0
 
LVL 1

Expert Comment

by:rlarner
ID: 1320952
<grumble> the tabs didn't come through properly on that code segment -- sorry.

PS If you feel like it, it would be great to send your dialog class to the CodeGuru archive too.
0
 

Author Comment

by:RJV
ID: 1320953
I tried the above and some variations of it. No luck. By chance I'd commented the callback part out as I wasn't getting anywhere with it. However, I hadn't tried your suggestion, probably as by now I've tried and checked everything under the sun, so I may have skipped something.

First, message==WM_COMMAND doesn't get you into the important part, so knocked that out. The HIWORD(wParam)==BN_CLICKED does get you there, even though I didn't have a chance to click anything. Still, the outcome was an apparently valid pDlg. However, in either of the following options I got an invalid hwnd:

  1) CListCtrl* pList = (CListCtrl*)pDlg->GetDlgItem(lst1);

  2) CListCtrl* pList =
     (CListCtrl*)pDlg->GetDlgItem(lst2)->GetDlgItem(0x01);

Note that option 2 was the only one that got me the right index to the item in the CListCtrl earlier.

Any suggestions or ideas on this?

RJV

0
 
LVL 1

Expert Comment

by:rlarner
ID: 1320954
OK, got it working.  Damn, MS Sucks!!!
For a while, I thought you were wrong about using lst2 - MS docs say that lst1 is the proper control ID to use.  However, after using WinSpy, I found you were right.
How I got this to work was, in the subclass, overload OnFileNameOK.  In your implementation of this procedure, get the list control through your option #2, and then iterate normally through the list of selected items.  Don't forget to calle the base class implementation of OnFileNameOK, otherwise your dialog will never go away! ;-]
<whew!!!!>
0
 

Author Comment

by:RJV
ID: 1320955
Hummm.... That's the one point I hadn't tried to get. Congratulations! Unfortunately I'll have to keep this for the future. Since things must move ahead (here) I decided to transfer a combination of a tree control with a list control which was in a dialog bar to a regular dialog. It took a bit of work, but in the end less than all of the testing I'd tried on the Win32 front.

Now instead of doing the above, the user sets check marks to each drive or folder, and file. It does mean a better visual result, and I have full control of what goes on. So, in the end, we have both solutions!

It sure would've been easier if Win32 let us pick everything, like you could (and, I suppose, still can) in the DOS only world!

RJV

0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
CSS Question.. 3 72
Snap images to the bottom of a div 5 62
Microsoft Edge 9 80
Swiper slider stops between pages 11 31
Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now