Click here to Skip to main content
Click here to Skip to main content

A File Open Dialog for the PocketPC 2002

, 26 Jan 2004
Rate this:
Please Sign up or sign in to vote.
An implementation of a full-browsing file open dialog.

Sample screenshot

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 #includes 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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

João Paulo Figueira
Software Developer Frotcom International
Portugal Portugal
I work on R&D for Frotcom International, a company that develops web-based fleet management solutions.
Follow on   Twitter   LinkedIn

Comments and Discussions

 
Questionhow to run .ppt file on smartdevice application PinmemberMember 412018925-Sep-08 0:38 
GeneralMak it work across a LAN Pinmemberjima2z6-Jan-07 4:22 
Generalshell open command PinmemberM i s t e r L i s t e r17-Oct-06 18:02 
GeneralCode ported to PPC2003 and WM5 under VS2005 [modified] PinmemberVincent_RICHOMME10-Aug-06 7:38 
GeneralRe: Code ported to PPC2003 and WM5 under VS2005 PinmemberJasonHo24-Aug-06 1:32 
QuestionRe: Code ported to PPC2003 and WM5 under VS2005 Pinmembergoddamnelectric9-Jan-07 23:06 
GeneralRe: Code ported to PPC2003 and WM5 under VS2005 Pinmembernoob_the_penguin7-Jun-07 1:32 
GeneralRe: Code ported to PPC2003 and WM5 under VS2005 PinmemberVincent_RICHOMME7-Jun-07 11:31 
GeneralFileOpen2: A Command Line Version [modified] PinmemberNaviGer27-May-06 0:23 
Hi,
I made some additions to João Paulo Figueira File Open Dialog.
 
The best would be, if I could upload the whole project with the source code here
 
Here is the description:
 
FileOpen2.exe
=============
 
A File Open Dialog for the PocketPC 2002 - 2005
The Original of this software was written by João Paulo Figueira,
first published at www.codeproject.com
 
With contributions from Dmitry Yakimov and tim2342
 
With additions for command line use, selection of
an initial directory and a 'File Input Window'.
The whole OLE stuff wa removed Wink | ;)
by NaviGer (Hans-Gerhard Flohr)
 
License: MIT / X11
 
New:
====
 
You can call the FileOpen2.exe with a command line parameter.
The command line parameter is a name of file, which contains
the open / save definitions.
The selected path (and the filename) are returned in the command file.
The previous contents of the command file is destroyed.
If the result begins with a '=' character, the user has pressed the ok button.
If the result begins with a '!' character, the user has pressed the cancel button.
 
Note: This Version runs only on Windows Mobile from WM2003 -2005
due to the use of the aygshell.dll
 
The following keys are decoded in the Command file:
===================================================
 
Title= :The title of the file open window
InitialDir= :The initial directory (may also contain the file name)
OpenText= :The text, which shall be shown in the dialog
 

Now the keys from the Microsoft CFileDialog Class definition:
CFileDialog dlg(TRUE, NULL, NULL, OFN_PROJECT);
CFileDialog(
BOOL bOpenFileDialog,
LPCTSTR lpszDefExt = NULL,
LPCTSTR lpszFileName = NULL,
DWORD dwFlags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
LPCTSTR lpszFilter = NULL,
...);
 
OpenMode=0 :1= Open, 0 Save
DefExt= :Default extension (currently not supported)
FileName= :The filename, to open or to which to save
Flags= :Flags according to the MS specification, only: OFN_HIDEREADONLY and OFN_OVERWRITEPROMPT
Filter= :File filter, according to the MS specification.GPS.
Must contain '|' as delimiters
 

Example of the contents of a command file:
==========================================
 
Title=Test Open
InitialDir=\Storage Card\POIObserver
OpenText=Open
OpenMode=1
DefExt=
FileName=
Flags=
Filter=GPS File (*.txt,*.gps)|*.txt;*.gps|All Files (*.*)|*.*||");
 
Example of the contents of the command file after returning:
============================================================
 
=\Storage Card\POIObserver\ZO_FS.TXT
when the user had pressed the cancel button or
!\Storage Card\POIObserver\ZO_FS.TXT
when the user had pressed the cancel button.
 
Remarks:
========
 
Non existing command file
-------------------------
You may also specify a name of a non existing file, the result of the selection
is written back to that file (if possible).
 
Why not a DLL?
--------------
Many software developers have problems with user written DLLs and .NET.
So it is easier, to write to a file, close it, and call FileOpen2.exe as a child process.
When the child process terminates, the result can be read from the same file.
 
MS specific:
------------
I noted, that MS is not able to interpret the '|' delimiters in the
file filter, although noted in the description.
So, if the calling FileOpen2 fails, you have to convert the filter string for the
CFileDialog:
 
CString csFilter = _T("GPS Log File (*.txt)"); csFilter += _T('|');
csFilter += _T("*.txt"); csFilter += _T('|');
csFilter += _T("GPS Log File (*.gps)"); csFilter += _T('|');
csFilter += _T("*.gps"); csFilter += _T("||");
 
int Position;
while((Position = csFilter.ReverseFind(_T('|'))) >= 0)
csFilter.SetAt(Position, _T('\0'));
 
or
--
 
TCHAR *tcFilter = _T("GPS ASC File (*.ASC)|*.ASC|All Files (*.*)|*.*||");
 
TCHAR *ptcPosition;
while((ptcPosition = _tcsrchr(tcFilter, _T('|'))) != NULL)
*ptcPosition = _T('\0');
 

 
-- modified at 13:28 Sunday 4th June, 2006
Questionanyone ported this to VS 2005? Pinmembermiggedy21-Mar-06 17:12 
AnswerRe: anyone ported this to VS 2005? PinmemberVincent_RICHOMME10-Aug-06 7:39 
QuestionManaged Code Equivalent of this? PinmemberVasudevan Deepak Kumar14-Mar-06 4:10 
AnswerRe: Managed Code Equivalent of this? PinmemberJoão Paulo Figueira14-Mar-06 4:16 
GeneralSaving Bitmaps in WinCE PinmemberJustin Clayden12-Dec-05 16:01 
QuestionCan I use that on my (GLP) project? Pinmemberhaamsteer17-Oct-05 9:10 
AnswerRe: Can I use that on my (GLP) project? PinmemberJoão Paulo Figueira17-Oct-05 11:18 
GeneralRe: Can I use that on my (GLP) project? Pinmemberfranprak6-Mar-07 17:35 
GeneralRe: Can I use that on my (GLP) project? PinmemberJoão Paulo Figueira6-Mar-07 22:59 
QuestionCan not found Deque.h Pinmemberlvguangchuan6-Oct-05 11:21 
AnswerRe: Can not found Deque.h PinmemberJoão Paulo Figueira6-Oct-05 12:18 
GeneralRe: Can not found Deque.h PinmemberNaviGer21-May-06 5:48 
GeneralRe: Can not found Deque.h PinmemberNaviGer21-May-06 5:52 
GeneralRe: Can not found Deque.h PinmemberJoão Paulo Figueira21-May-06 6:16 
GeneralRe: Can not found Deque.h [modified] PinmemberAndy Byron28-Sep-06 7:14 
GeneralSmall improvements PinsussDmitry Yakimov18-Aug-05 5:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web01 | 2.8.140827.1 | Last Updated 27 Jan 2004
Article Copyright 2003 by João Paulo Figueira
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid