Solved

CFileDialog multiple selection including folders

Posted on 1998-08-18
9
573 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Advice on what platform to use for a web app for AWS 3 94
Web Development Tools for MVC 3 75
Specific format 21 182
wordmultiple challenge 12 121
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 …
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

895 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

14 Experts available now in Live!

Get 1:1 Help Now