有没有办法选择哪些文件通过标准的OPENFILE对话框显示给用户? [英] Is there a way to choose which files are displayed to the user via the standard OPENFILE dialogs?

查看:252
本文介绍了有没有办法选择哪些文件通过标准的OPENFILE对话框显示给用户?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Vista引入了一个界面:IFileDialog :: SetFilter,它允许我为每个潜在的文件名设置一个过滤器,以查看是否应该显示给用户。

Vista introduced an interface: IFileDialog::SetFilter, which allows me to setup a filter that will be called for every potential filename to see if it should be shown to the user.

Microsoft在Windows 7中删除了它,并且在XP中不支持它。

Microsoft removed that in Windows 7, and didn't support it in XP.

我试图自定义我们的打开文件对话框,哪些文件显示给最终用户。这些文件在内部用产品代码标记 - 文件名本身没有任何要过滤的文件(因此文件扩展过滤器在这里不起作用 - =我需要实际询问每个文件以查看它是否在额外的过滤器内

I am trying to customize the our Open file dialog so that I can control which files are displayed to the end user. These files are marked internally with a product-code - there isn't anything in the filename itself to filter on (hence file extension filters are not useful here -= I need to actually interrogate each one to see if it is within the extra filter parameters that our users specified).

我猜想Microsoft移除了SetFilter接口,因为太频繁了太慢了。我可以想象各种类似的想法,这对于网络和云存储和你有什么不好扩展好。

I would guess that Microsoft removed the SetFilter interface because too often it was too slow. I can imagine all sorts of similar ideas to this one which don't scale well for networks and cloud storage and what have you.

但是,我需要知道,如果有是一个可以实现相同目标的替代接口,或者如果我真的仅限于在文件对话框中查看文件扩展名以进行过滤?

However, I need to know if there is an alternative interface that accomplishes the same goal, or if I really am restricted to only looking at the file extension for filtering purposes in my File dialogs?

后续:

在进一步查看CDN_INCLUDEITEM(需要使用预先版本的OPENFILENAME)之后,我发现这是最无用的API可想而知。它只过滤非文件系统对象。换句话说,你不能使用它来过滤文件。或文件夹。过滤99.99%的文件打开或保存对话框的时间。难以置信!

Follow-up:
After looking further into CDN_INCLUDEITEM, which requires the pre-vista version of OPENFILENAME, I have found that this is the most useless API imaginable. It only filters NON-filesystem objects. In other words, you can't use it to filter files. Or folders. The very things one would filter 99.99% of the time for a file open or save dialog. Unbelievable!

有一个非常古老的 Paul DiLascia的文章,它提供了每次更新列表视图时从列表视图控件中删除每个违规文件名的技术。

There is a very old article by Paul DiLascia which offers the technique of removing each offending filename from the list view control each time the list view is updated.

我知道从苦的经验,列表视图可以更新随着时间的推移。如果你正在查看一个大文件夹(许多项目)或连接是有点慢(重负载服务器和/或大量的文件),然后文件添加到对话框片段。因此,我们必须重复过滤出有问题的文件名。

However, I know from bitter experience that the list view can update over time. If you're looking at a large folder (many items) or the connection is a bit slow (heavily loaded server and/or large number of files), then the files are added to the dialog piecemeal. So one would have to filter out offending filenames repeatedly.

事实上,我们当前的自定义文件打开对话框使用定时器来定期查看文件名列表,看看是否存在给定模式的任何文件,以便实现另一控制。否则,可以检查这些文件的存在,找不到,但稍后,视图更新有更多的文件名,没有事件发送到您的对话框,以指示视图已更改。事实上,我的经验,不得不编写和维护常见的控制文​​件对话框的代码多年来,微软并不是非常cluefull,当谈到如何写这样的事情。事件不完整,在无用的时间发送,不必要时重复,并且不存在整类有用的通知。

In fact, our current customized file open dialog uses a timer to look at the view's list of filenames periodically to see if any files of a given pattern exist, in order to enable another control. Otherwise it's possible to check for the existence of these files, find none, but a moment later the view updates to have more filenames, and no events are sent to your dialog to indicate that the view has been changed. In fact, my experience with having to write and maintain code for the common controls file dialogs over the years has been that Microsoft is not very cluefull when it comes to how to write such a thing. Events are incomplete, sent at not-useful times, repeated when not necessary, and whole classes of useful notifications don't exist.

很遗憾,我可能需要放弃哦这个想法。除非有人想到我可以跟上在用户尝试与其交互时自发改变的视图(即,从列表视图中删除条目并改变用户的视觉位置将是不方便的,或突出显示的文件或滚动位置等)。

Sadly, I think I might have to give up oh this idea. Unless someone has a thought as to how I might be able to keep up with the view spontaneously changing while the user is trying to interact with it (i.e. it would be awkward to go deleting out entries from the list view and changing the user's visual position, or highlighted files, or scroll position, etc.)

推荐答案

您需要初始化CFileDialog的回调。然后,您需要处理 CDN_INCLUDEITEM通知代码以包含或排除项目。

You need to initialise the callbacks for your CFileDialog. Then you need to process CDN_INCLUDEITEM notification code to include or exclude items.

您还可以选中这篇很棒的文章。作者使用除了回调

You can also check this great article. The author uses some other approaches in addition to callbacks

这篇关于有没有办法选择哪些文件通过标准的OPENFILE对话框显示给用户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆