File Open Dialog with Multiple Selection – Part 3: Cutting the Dog Tail

First two articles in this series show how to deal with a large number of selected items, by manipulating the OPENFILENAME::lpstrFile buffer, either for old style or Vista-style Open File dialogs. However, if the target system is Windows Vista or newer, we should prefer getting rid of old stuff and use only Vista-style dialogs.
So, let’s cut the dog’s tail as fast and painless as possible!

Using IFileOpenDialog to collect the results

Example 5

This time, we’ve used Common Item Dialog API (IFileOpenDialog interface and so on) instead of the “classic” CFileDialog::GetStartPosition and CFileDialog::GetNextPathName. That allows to step beyond the old stuff limits without overriding any CFileDialog method and without doing any other type of “dancing on the rope”.

Demo application

Vista File Open Dialog with Multiple Selection - Demo

Vista File Open Dialog with Multiple Selection – Demo

The demo application demonstrates how to grab File Open dialog results by using Common Item Dialog API. For demo/testing purpose it has also a function which uses the old way of CFileDialog::GetNextPathName. Just uncheck “Use IFileOpenDialog”, push “Open…” button, select a large number of items from the open file dialog list, then see the difference.

Demo project download: Vista File Open Dialog with Multiple Selection (181)

Notes

  • Common Item Dialog API is supported on Windows Vista and newer.
  • CFileDialog with Vista style is implemented in Visual Studio 2008 and newer.
  • Of course may be also other solutions. For example, someone still would prefer to derive from CFileDialog in order to put all COM stuff in a single place, for making others’ life easier.
  • For any constructive remark or alternative solution(s), please do not hesitate and leave a comment!

Resources

  • MSDN and Windows Dev Center (see the links in the previous articles).

See also

Leave a Reply