Solved

CFileDialog multiple selection including folders

Posted on 1998-08-18
9
583 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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
 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how to extract window origin in spring 2 78
Using YubiKey with REST API application 2 135
unix example issues 18 106
Import data into excel from web page 10 109
Most of the sites are being standardized with W3C Web Standards. W3C provides lot of web standard services to the web. They have the web specification, process and documentation for all the web standards. You can apply HTML, CSS and Accessibility st…
What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

679 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