Introduction
On the PocketPC, the File Open dialog is not very versatile. In fact, you are limited to a small number of directories, which may be too limiting for your own purposes. I started to think about a possible solution for this problem after reading a post in the Mobile / Embedded forum, where a reader complains about the limitations of CFileDialog
.
This article describes a solution for this problem, by implementing a more advanced File Open dialog.
CFileOpenDlg
The dialog is implemented in the CFileOpenDlg
class in the demo application. Its usage is very straightforward, as you can see from the sample below:
void CChildView::OnFileOpen()
{
CFileOpenDlg dlg;
if(IDOK == dlg.DoModal())
{
CString strFullPath(dlg.GetPath());
strFullPath += dlg.GetFileName();
MessageBox(strFullPath);
}
}
In order to get the full path name, you have to append the path and the file name, as reported by GetPath()
and GetFileName()
.
File filters are set through the SetFilter
method. By default, the dialog uses SetFilter("*")
, so all files are displayed. Please note that this filter will only affect file browsing, not directory browsing.
Using The Class
Unfortunately, this class is not completely encapsulated because it needs some resources, namely the bitmaps for the list header and the dialog itself. When porting this code to your application, some cutting and pasting will be necessary. Apart from that, you will need the CExDialog
and CExDlgEngine
classes in order to be able to print a header in the dialog. This code is heavily based on prior art, which you can find in this article: How can I create a dialog title like in Control Panel property pages?
Limitations and Future Improvements
There are a number of limitations that will be addressed in future updates:
- On-demand loading of the directory tree. The loading is now made in just one step and, if you have a complex directory tree, this will show in a slower operation. By loading the tree in an on-demand fashion, both start-up time and memory consumption will be greatly reduced.
- File sorting. There is no provision for sorting files in this dialog.
Release History
26 January 2004
Third release in CodeProject with the following updates:
- Folder tree is loaded on demand.
- Folders use the system image list icons.
- File list now supports sorting (ascending and descending) on any column.
- The sorted column displays a light grey background and the header shows an arrow reflecting the sort direction.
15 May 2003
Removed references to spurious #include
s and symbols.
14 May 2003
Second release in CodeProject with the following updates:
- The device name is reported in the tree view.
- The file list now supports file icons.
- The OK and Cancel buttons were replaced by toolbar buttons (the cancel button is not very nice, but hey - I'm not a graphics designer)
- Views can be switched between split view, tree view and list view.
- You can move the split between tree and list by clicking and dragging.
27 Mar 2003
First release in CodeProject.
Thank You
Amit Dey provided the code and idea for using the system image list. Also, he provided guidance when I completely goofed the first time I tried it.