Showing a Windows context menu for multiple items

我只是一个虾纸丫 提交于 2020-01-01 18:15:08

问题


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.

I use SHParseDisplayName to get a pidl for a filename. 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. You can find some excellent information here:

  • [xplorer²] — Advanced shell context menu 🕗


来源:https://stackoverflow.com/questions/2208284/showing-a-windows-context-menu-for-multiple-items

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!