From: Mikel on
Hi,
I need to open a CFileDialog so the user can open a file, and I would
like the dialog to only show files without extension. Can it be done?
I've tried "My kind of file (*)|*|All files (*.*)|*.*||" and "My kind
of file (*.)|*.|All files (*.*)|*.*||" with no luck. The first one
shows all the files (as I had expected) and the second one shows none.

Any ideas?
Thanks
From: David Ching on
"Mikel" <mikel.luri(a)gmail.com> wrote in message
news:7e244c69-f020-4b3b-8966-dedf66edd2d9(a)b7g2000yqk.googlegroups.com...
> Hi,
> I need to open a CFileDialog so the user can open a file, and I would
> like the dialog to only show files without extension. Can it be done?
> I've tried "My kind of file (*)|*|All files (*.*)|*.*||" and "My kind
> of file (*.)|*.|All files (*.*)|*.*||" with no luck. The first one
> shows all the files (as I had expected) and the second one shows none.
>

In a command prompt, "dir *." shows subfolders and only files without an
extension. But in a File Open dialog, if you type "*." it doesn't show
files without an extension, unfortunately. So I'm out of ideas.

Sorry,
David


From: JCO on
I guess you can programmatically get all files, search for NO "." and NO
Extensions in the filename, then populate a list box with only files.
Depends on what you want to do with these files once you've identified them.

"Mikel" <mikel.luri(a)gmail.com> wrote in message
news:7e244c69-f020-4b3b-8966-dedf66edd2d9(a)b7g2000yqk.googlegroups.com...
> Hi,
> I need to open a CFileDialog so the user can open a file, and I would
> like the dialog to only show files without extension. Can it be done?
> I've tried "My kind of file (*)|*|All files (*.*)|*.*||" and "My kind
> of file (*.)|*.|All files (*.*)|*.*||" with no luck. The first one
> shows all the files (as I had expected) and the second one shows none.
>
> Any ideas?
> Thanks

From: Hector Santos on
Mikel wrote:

> Hi,
> I need to open a CFileDialog so the user can open a file, and I would
> like the dialog to only show files without extension. Can it be done?
> I've tried "My kind of file (*)|*|All files (*.*)|*.*||" and "My kind
> of file (*.)|*.|All files (*.*)|*.*||" with no luck. The first one
> shows all the files (as I had expected) and the second one shows none.
>
> Any ideas?
> Thanks


Do you don't want directories? or the ability to switch? Just a
selection for a particular folder?

Anyway, for our product we have a vast implementation of all various
kinds of Open/Save File/Directory displays.

In some we don't want directories shown, and others we just want
directories, etc, or we have a virtual display where the file elements
are not local but coming from an virtual channel (RPC server). Like
our web server configuration getting a listing of SSL Certificates
from a remote RPC Server storage.

The Open File/Save File has the OPENFILENAME element (m_ofn) that you
can use to highly customize the display.

If you use a template, then you separate the three things:

Filename LISTBOX towards the right
Directory TreeView towards the left
Drive Combobox towards the bottom

This is the same as the NON-EXPLORER NT style display but with our own
template, you can layout it anyway you want, you can hide the
directory and drive controls so they user only sees the file listbox.

However, as far as I am aware, although there is a notification for
items that will get listed, you can't exclude files and directories,
at least we never figured it out.

See the CDN_INCLUDEITEM notification message which is used with the
OFN_ENABLEINCLUDENOTIFY | OFNENABLEHOOK flags when using a
m_ofn.lpfnHook callback notification, for example:

CFileDialog fd(TRUE);

fd.m_ofn.Flags |= OFN_ENABLEHOOK;
fd.m_ofn.Flags |= OFN_ENABLEINCLUDENOTIFY;
fd.m_ofn.lpfnHook = FileDialogHook;
fd.DoModal();

In the FileDialogHook(), you have something like this:

UINT_PTR CALLBACK FileDialogHook(
HWND hdlg,
UINT uiMsg,
WPARAM wParam,
LPARAM lParam)
{
if (uiMsg == WM_NOTIFY && lParam) {
OFNOTIFYEX *nex = (OFNOTIFYEX *)lParam;
if (nex->hdr.code == CDN_INCLUDEITEM) {
// see docs to use lParam with the IShellFolder object
}
}
return 0;
}

You can then get a notification for each item that is going to be
displayed and even though the docs return 0 to exclude the item,
return non-zero to include the item, in reality it always includes
files and directories. In fact, the MSDN note for CDN_INCLUDEITEM says:

Remarks:

The dialog box always includes items that have both the
SFGAO_FILESYSTEM and SFGA_FILESYSANCESTER attributes, regardless
of the value returned by CDN_INCLUDEITEM.

So that probably explained why we never got it to filter right.

So for these special cases, we found it easier to just create your own
Dialog with a Listbox etc, and use a FindFirstFile(), FindFirstNext()
to do exactly what you want.

So create a dialog box that "looks" like Explorer or just have a
selection list box (m_lbox), and in the InitDialog() for the dialog,
do a directory scan and AddString to the listbox:

WIN32_FIND_DATA fd = {0};
HANDLE fh = FindFirstFile("*.",&fd);
if (fh != INVALID_HANDLE_VALUE) {
do {
if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) continue;

//
// WE GOT A NON-DIRECTORY *. FILE!
//

m_listbox.AddString(fd.cFileName);

} while (FindNextFile(fh,&fd));
FindClose(fh);
}

That works very well and you have full control :)

--
HLS
From: Mikel on
On 15 mayo, 06:37, Hector Santos <sant9...(a)gmail.com> wrote:
> Mikel wrote:
> > Hi,
> > I need to open a CFileDialog so the user can open a file, and I would
> > like the dialog to only show files without extension. Can it be done?
> > I've tried "My kind of file (*)|*|All files (*.*)|*.*||" and "My kind
> > of file (*.)|*.|All files (*.*)|*.*||" with no luck. The first one
> > shows all the files (as I had expected) and the second one shows none.
>
> > Any ideas?
> > Thanks
>
> Do you don't want directories? or the ability to switch? Just a
> selection for a particular folder?

What I need is a normal CFileDialog, which only shows files without
extension (and directores, so the user can switch to another one). I
need to select files created with an oooold MSDOS application (over
which I have no control at all), whose data files have no extension,
and I would like to filter those files out, just as I would filter
*.doc, *.txt, etc.

>
> Anyway, for our product we have a vast implementation of all various
> kinds of Open/Save File/Directory displays.
>
> In some we don't want directories shown, and others we just want
> directories, etc, or we have a virtual display where the file elements
> are not local but coming from an virtual channel (RPC server). Like
> our web server configuration getting a listing of SSL Certificates
> from a remote RPC Server storage.
>
> The Open File/Save File has the OPENFILENAME element (m_ofn) that you
> can use to highly customize the display.
>
> If you use a template, then you separate the three things:
>
>     Filename    LISTBOX towards the right
>     Directory   TreeView towards the left
>     Drive       Combobox towards the bottom
>
> This is the same as the NON-EXPLORER NT style display but with our own
> template, you can layout it anyway you want, you can hide the
> directory and drive controls so they user only sees the file listbox.
>
> However, as far as I am aware, although there is a notification for
> items that will get listed, you can't exclude files and directories,
> at least we never figured it out.
>
> See the CDN_INCLUDEITEM notification message which is used with the
> OFN_ENABLEINCLUDENOTIFY | OFNENABLEHOOK flags when using a
> m_ofn.lpfnHook callback notification, for example:
>
>    CFileDialog fd(TRUE);
>
>    fd.m_ofn.Flags |= OFN_ENABLEHOOK;
>    fd.m_ofn.Flags |= OFN_ENABLEINCLUDENOTIFY;
>    fd.m_ofn.lpfnHook = FileDialogHook;
>    fd.DoModal();
>
> In the FileDialogHook(), you have something like this:
>
> UINT_PTR CALLBACK FileDialogHook(
>         HWND hdlg,
>         UINT uiMsg,
>         WPARAM wParam,
>         LPARAM lParam)
> {
>      if (uiMsg == WM_NOTIFY && lParam) {
>          OFNOTIFYEX *nex = (OFNOTIFYEX *)lParam;
>          if (nex->hdr.code == CDN_INCLUDEITEM) {
>             // see docs to use lParam with the IShellFolder object
>          }
>      }
>      return 0;
>
> }
>
> You can then get a notification for each item that is going to be
> displayed and even though the docs return 0 to exclude the item,
> return non-zero to include the item, in reality it always includes
> files and directories. In fact, the MSDN note for CDN_INCLUDEITEM says:
>
>    Remarks:
>
>    The dialog box always includes items that have both the
>    SFGAO_FILESYSTEM and SFGA_FILESYSANCESTER attributes, regardless
>    of the value returned by CDN_INCLUDEITEM.
>
> So that probably explained why we never got it to filter right.
>
> So for these special cases, we found it easier to just create your own
> Dialog with a Listbox etc, and use a FindFirstFile(), FindFirstNext()
> to do exactly what you want.
>
> So create a dialog box that "looks" like Explorer or just have a
> selection list box (m_lbox), and in the InitDialog() for the dialog,
> do a directory scan and AddString to the listbox:
>
>     WIN32_FIND_DATA fd = {0};
>     HANDLE fh = FindFirstFile("*.",&fd);
>     if (fh != INVALID_HANDLE_VALUE) {
>         do {
>           if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) continue;
>
>           //
>           // WE GOT A NON-DIRECTORY *. FILE!
>           //
>
>           m_listbox.AddString(fd.cFileName);
>
>         } while (FindNextFile(fh,&fd));
>         FindClose(fh);
>     }
>
> That works very well and you have full control :)
>
> --
> HLS

Thanks for all the info. It seems there is no straightforward way to
do what I want. I'll check your suggestions when I have a little more
time. Right now, the urgent thing is to read the file properly.
Thanks again