我是第一次提问,不过这个问题有点难度
希望没有把握或者没有接触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.