开发者

Showing a Windows context menu for multiple items

开发者 https://www.devze.com 2022-12-19 13:09 出处:网络
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 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?


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
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号