如何实现多个文件对象的IContextMenu菜单?(Shell编程)

vocanicy 2008-06-01 04:00:54
我是第一次提问,不过这个问题有点难度
希望没有把握或者没有接触Shell编程的朋友不要回些无关的内容

我做了一个文件查找工具,类似Windows的文件查找功能,不过查找的条件更灵活些。我将查找的结果添加到CListCtrl控件中,然后利用IShellFoler、IContextMenu等Shell接口实现了查找结果的右键Shell菜单,就是和在文件夹中的右键菜单相同。但是用过IShellFolder::GetUIObjectOf函数的朋友都知道,它可以返回某个文件夹下,一个或者多个文件对象的IContextMenu接口。但是它的前提是选中的多个文件必须是在同一文件夹内。

因为我是搜索包含子文件夹的,所以查找结果中有不同文件夹的文件
我想实现选中多个文件(其中有不同一文件夹的文件),也能弹出Shell菜单。

Windows的查找文件功能在结果列表中选择多个文件(不同文件夹下的文件)是可以弹出菜单的,不知道它是如何实现的呢?
举个例子,你查找C盘所有文件,你选中查找结果中的任意多个文件,都可以弹出相应的右键菜单,而且菜单中的“属性”功能可以统计所选文件个数、大小等信息。

我需要的答案就是如何实现选中多个文件(其中有不同一文件夹的文件)的Shell菜单。


我查过一些资料,下面是摘自微软网站上的一篇文章
http://www.microsoft.com/msj/0497/wicked/wicked0497.aspx
按我的理解这篇文章的意思是没什么办法
但我想既然微软自己的文件查找功能可以实现,应该还是有办法的


What About Multiple Items?
DoExplorerMenu does not provide a solution for displaying an Explorer context menu for more than one item. You can see what I mean by bringing up the Windows 95 (or Windows NT 4.0) Find utility and searching on *.* to generate a list of every file and folder on, say, drive C. Once the list is displayed, select several objects of different types (for example, a .TXT file, an .XLS file, and a folder) and then right-click one of the items. A composite context menu forms from commands in the items' individual context menus.
Unfortunately, there is not a convenient mechanism (at least none that I know of) to build a composite context menu using operating system-supplied functions. For example, there is no magic way to call QueryContextMenu and have it fill in a context menu pertaining to multiple items. When I asked Microsoft how they did it, the response I got was something like "Well, we kludged it up with some code that we're not too proud of, and our code also relies on some information that's available only to Explorer, so don't try this at home."
The obvious solution is to display Explorer menus for just one item at a time. If you select multiple items and click one of them with the right mouse button, either the context menu for that item should be displayed or nothing should be displayed. You might get clever and call IContextMenu:: QueryContextMenu once for each item (each time using a separate HMENU) and then combine all the unique items into one composite menu, but I wouldn't go to that much trouble unless I had to. Let your conscience be your guide. Meanwhile, cross your fingers and hope that this is an omission Microsoft will remedy in a future version of Windows.
...全文
366 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
vocanicy 2008-06-05
  • 打赏
  • 举报
回复
谢谢楼上提供的资料

我了解过这方面的内容

虚拟文件夹虽然可以实现将查找结果放入其中,但是它的IContextMenu接口是需要完全自己实现的
也就是说和系统Shell提供的菜单是两回事

虽然自己做可以模拟类似的效果,但是无法实现和系统查找中提供的相同功能
如果需要完全自己做的话,不如直接在我的应用程序中自己实现;如果在虚拟文件夹组件中实现IContextMenu接口,倒有点舍近求远的味道

看来是无法直接利用系统这个功能
vocanicy 2008-06-02
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 wangk 的回复:]
产生一个临时的虚拟的文件夹?比如类似控制面板,打印机这样的虚拟文件夹?
把结果放在里面?
[/Quote]

这个我考虑过
不过不是很了解虚拟文件夹
我查过相关资料,暂时也没有头绪

能否告知结果是用什么接口添加?需要了解哪些内容?
wangk 2008-06-02
  • 打赏
  • 举报
回复
产生一个临时的虚拟的文件夹?比如类似控制面板,打印机这样的虚拟文件夹?
把结果放在里面?
vocanicy 2008-06-02
  • 打赏
  • 举报
回复
顶一下
wangk 2008-06-02
  • 打赏
  • 举报
回复
可以参考下面的文章:


Writing Namespace Extensions
vocanicy 2008-06-01
  • 打赏
  • 举报
回复
还有个问题,我调用IContextMenu接口的QueryContextMenu函数来生成菜单的速度有些慢
piContextMenu->QueryContextMenu(hMenu, 0, 1, 0x7fff, CMF_NORMAL);

不知道有没有什么技巧可以提高速度?

如果答案能解决我的问题,可以另外再加一些分

2,644

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 硬件/系统
社区管理员
  • 硬件/系统社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧