public void ShowContextMenu(Point pointScreen) { IntPtr intPtr = IntPtr.Zero; IntPtr zero = IntPtr.Zero; IntPtr zero2 = IntPtr.Zero; IntPtr zero3 = IntPtr.Zero; try { if (null == this._arrPIDLs) { this.ReleaseAll(); } else if (!this.GetContextMenuInterfaces(this._oParentFolder, this._arrPIDLs, out zero)) { this.ReleaseAll(); } else { intPtr = ShellContextMenu.CreatePopupMenu(); int num = this._oContextMenu.QueryContextMenu(intPtr, 0u, 1u, 30000u, ShellContextMenu.CMF.EXPLORE | (((Control.ModifierKeys & Keys.Shift) != Keys.None) ? ShellContextMenu.CMF.EXTENDEDVERBS : ShellContextMenu.CMF.NORMAL)); Marshal.QueryInterface(zero, ref ShellContextMenu.IID_IContextMenu2, out zero2); Marshal.QueryInterface(zero, ref ShellContextMenu.IID_IContextMenu3, out zero3); this._oContextMenu2 = (ShellContextMenu.IContextMenu2)Marshal.GetTypedObjectForIUnknown(zero2, typeof(ShellContextMenu.IContextMenu2)); this._oContextMenu3 = (ShellContextMenu.IContextMenu3)Marshal.GetTypedObjectForIUnknown(zero3, typeof(ShellContextMenu.IContextMenu3)); uint num2 = ShellContextMenu.TrackPopupMenuEx(intPtr, ShellContextMenu.TPM.RETURNCMD, pointScreen.X, pointScreen.Y, base.Handle, IntPtr.Zero); ShellContextMenu.DestroyMenu(intPtr); intPtr = IntPtr.Zero; if (num2 != 0u) { this.InvokeCommand(this._oContextMenu, num2, this._strParentFolder, pointScreen); } } } catch { throw; } finally { if (intPtr != IntPtr.Zero) { ShellContextMenu.DestroyMenu(intPtr); } if (zero != IntPtr.Zero) { Marshal.Release(zero); } if (zero2 != IntPtr.Zero) { Marshal.Release(zero2); } if (zero3 != IntPtr.Zero) { Marshal.Release(zero3); } this.ReleaseAll(); } }
private void InvokeContextMenuDefault(FileInfo[] arrFI) { this.ReleaseAll(); IntPtr intPtr = IntPtr.Zero; IntPtr zero = IntPtr.Zero; try { this._arrPIDLs = this.GetPIDLs(arrFI); if (null == this._arrPIDLs) { this.ReleaseAll(); } else if (!this.GetContextMenuInterfaces(this._oParentFolder, this._arrPIDLs, out zero)) { this.ReleaseAll(); } else { intPtr = ShellContextMenu.CreatePopupMenu(); int num = this._oContextMenu.QueryContextMenu(intPtr, 0u, 1u, 30000u, ShellContextMenu.CMF.DEFAULTONLY | (((Control.ModifierKeys & Keys.Shift) != Keys.None) ? ShellContextMenu.CMF.EXTENDEDVERBS : ShellContextMenu.CMF.NORMAL)); uint menuDefaultItem = (uint)ShellContextMenu.GetMenuDefaultItem(intPtr, false, 0u); if (menuDefaultItem >= 1u) { this.InvokeCommand(this._oContextMenu, menuDefaultItem, arrFI[0].DirectoryName, Control.MousePosition); } ShellContextMenu.DestroyMenu(intPtr); intPtr = IntPtr.Zero; } } catch { throw; } finally { if (intPtr != IntPtr.Zero) { ShellContextMenu.DestroyMenu(intPtr); } this.ReleaseAll(); } }
public int ShowContextMenu(Point pointScreen, string[] AddedItems) { IntPtr intPtr = IntPtr.Zero; IntPtr zero = IntPtr.Zero; IntPtr zero2 = IntPtr.Zero; IntPtr zero3 = IntPtr.Zero; int num = -1; int result; try { if (null == this._arrPIDLs) { this.ReleaseAll(); result = -2; } else if (!this.GetContextMenuInterfaces(this._oParentFolder, this._arrPIDLs, out zero)) { this.ReleaseAll(); result = -2; } else { intPtr = ShellContextMenu.CreatePopupMenu(); int num2 = this._oContextMenu.QueryContextMenu(intPtr, 0u, 1u, 30000u, ShellContextMenu.CMF.EXPLORE | (((Control.ModifierKeys & Keys.Shift) != Keys.None) ? ShellContextMenu.CMF.EXTENDEDVERBS : ShellContextMenu.CMF.NORMAL)); Marshal.QueryInterface(zero, ref ShellContextMenu.IID_IContextMenu2, out zero2); Marshal.QueryInterface(zero, ref ShellContextMenu.IID_IContextMenu3, out zero3); this._oContextMenu2 = (ShellContextMenu.IContextMenu2)Marshal.GetTypedObjectForIUnknown(zero2, typeof(ShellContextMenu.IContextMenu2)); this._oContextMenu3 = (ShellContextMenu.IContextMenu3)Marshal.GetTypedObjectForIUnknown(zero3, typeof(ShellContextMenu.IContextMenu3)); for (int i = 0; i < AddedItems.Length; i++) { ShellAPI.InsertMenu(intPtr, (uint)i, ShellAPI.MFT.BYPOSITION, (uint)(30001 + i), AddedItems[i]); } ShellAPI.InsertMenu(intPtr, (uint)AddedItems.Length, ShellAPI.MFT.SEPARATOR | ShellAPI.MFT.BYPOSITION, (uint)(30001 + AddedItems.Length), "-"); uint num3 = ShellContextMenu.TrackPopupMenuEx(intPtr, ShellContextMenu.TPM.RETURNCMD, pointScreen.X, pointScreen.Y, base.Handle, IntPtr.Zero); ShellContextMenu.DestroyMenu(intPtr); intPtr = IntPtr.Zero; if (AddedItems.Length > 0 && num3 >= 30001u && (ulong)num3 <= (ulong)((long)(AddedItems.Length - 1 + 30001))) { num = (int)(num3 - 30001u); } else if (num3 != 0u) { this.InvokeCommand(this._oContextMenu, num3, this._strParentFolder, pointScreen); } result = num; } } catch { Console.WriteLine("Error in Context Menu generation"); result = -1; } finally { if (intPtr != IntPtr.Zero) { ShellContextMenu.DestroyMenu(intPtr); } if (zero != IntPtr.Zero) { Marshal.Release(zero); } if (zero2 != IntPtr.Zero) { Marshal.Release(zero2); } if (zero3 != IntPtr.Zero) { Marshal.Release(zero3); } this.ReleaseAll(); } return(result); }