Solved

CFileDialog multiple selection including folders

Posted on 1998-08-18
9
592 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: 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

Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

Question has a verified solution.

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

Preface In the first article: A Better Website Login System (http://www.experts-exchange.com/A_2902.html) I introduced the EE Collaborative Login System and its intended purpose. In this article I will discuss some of the design consideratio…
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…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

617 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