Exemplo n.º 1
0
        private void Initialize(IReadOnlyList <ShellObject> items)
        {
            var pidls  = items.Select(item => ShellContextMenuNativeMethods.ILFindLastID(item.PIDL)).ToArray();
            var parent = (ShellContainer)items.Select(item => item.Parent).DistinctByIEquatable().Single();

            parent.NativeShellFolder.GetUIObjectOf(IntPtr.Zero, (uint)pidls.Length, pidls, typeof(IContextMenu).GUID, 0, out var result);
            _contextMenu    = (IContextMenu)Marshal.GetTypedObjectForIUnknown(result, typeof(IContextMenu));
            _messageHandler = new ShellContextMenuMessageHandler(_contextMenu);
        }
Exemplo n.º 2
0
        public void ShowIn(UIElement element)
        {
            var point = element.PointToScreen(Mouse.GetPosition(element));

            var popupMenu = ShellContextMenuNativeMethods.CreatePopupMenu();

            _contextMenu.QueryContextMenu(popupMenu, 0, CmdFirst, CmdLast, CMF.EXPLORE);

            int command = ShellContextMenuNativeMethods.TrackPopupMenuEx(popupMenu, TPM.TPM_RETURNCMD, (int)point.X, (int)point.Y, _messageHandler.Handle, IntPtr.Zero);

            if (command > 0)
            {
                _messageHandler.InvokeCommand(command - CmdFirst);
            }
        }