简体   繁体   English

显示多个项目的Windows上下文菜单

[英]Showing a Windows context menu for multiple items

I have an application that lists files, and I allow the user to right-click on a file and my application shows the Windows context menu for the selected file. 我有一个列出文件的应用程序,并且允许用户右键单击一个文件,并且我的应用程序显示所选文件的Windows上下文菜单。

I use SHParseDisplayName to get a pidl for a filename. 我使用SHParseDisplayName获取文件名的pidl。 Then I bind to the parent object: 然后我绑定到父对象:

IntPtr pidlLast = IntPtr.Zero;
SHBindToParent(pidl, typeof(IShellFolder).GUID, out oShellFolder, out pidlLast);

After I have the parent I can get build the context menu: 有了父母之后,我可以构建上下文菜单:

IntPtr result = IntPtr.Zero;
IShellFolder shellFolder = (IShellFolder)oShellFolder;
shellFolder.GetUIObjectOf(windowHandle, (uint)pidls.Count, 
        pidls.ToArray(), typeof(IContextMenu).GUID, 0, out result);

This works perfectly for 1 item or for items with the same parent, but how do I display a context menu for items with different parents? 这非常适合1个项目或具有相同父项的项目,但是如何显示具有不同父项的项的上下文菜单?

For future reference, apparently you can use CDefFolderMenu_Create2 to create a context menu for multiple shell items. 为了将来参考,您显然可以使用CDefFolderMenu_Create2为多个外壳项目创建上下文菜单。 You can find some excellent information here: 您可以在这里找到一些很好的信息:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM