BExplorer.Shell.ShellContextMenu.ShowContextMenu C# (CSharp) Method

ShowContextMenu() public method

public ShowContextMenu ( Point pos, int type, System.Boolean shouldShow = true ) : int
pos Point
type int
shouldShow System.Boolean
return int
    public int ShowContextMenu(Point pos, int type = 0, Boolean shouldShow = true) {
      if (type == 0) {
        var newItems = this.GetNewContextMenuItems();
        using (ContextMenu menu = new ContextMenu()) {
          Populate(menu, CMF.EXPLORE);
          int command = User32.TrackPopupMenuEx(menu.Handle, TPM.TPM_RETURNCMD, pos.X, pos.Y, m_MessageWindow.Handle, IntPtr.Zero);
          if (command > 0) {
            var cmdID = command - m_CmdFirst;
            var verb = cmdID == 1 ? "newFolder" : cmdID == 2 ? ".lnk" : newItems[(int)cmdID - 3];
            var item = Marshal.StringToHGlobalUni(verb);
            this._ShellView.IsRenameNeeded = true;
            InvokeCommand(item, pos, Marshal.StringToHGlobalAnsi(verb));
          }
        }
        return 0;
      } else {
        using (ContextMenu menu = new ContextMenu()) {
          Populate(menu, CMF.EXPLORE);
          var submenuHandle = User32.GetSubMenu(menu.Handle, 0);
          if (shouldShow) {
            int command = User32.TrackPopupMenuEx(
                submenuHandle == IntPtr.Zero ? menu.Handle : submenuHandle, TPM.TPM_RETURNCMD, pos.X, pos.Y, m_MessageWindow.Handle, IntPtr.Zero
            );

            if (command > 0) InvokeCommand((IntPtr)(command - m_CmdFirst), pos, (IntPtr)(command - m_CmdFirst));
          }

          return User32.GetMenuItemCount(submenuHandle == IntPtr.Zero ? menu.Handle : submenuHandle);
        }
      }
    }

Same methods

ShellContextMenu::ShowContextMenu ( Control control, Point pos, CMF aditionalFlags, bool IsOnEmpty = false ) : void

Usage Example

    private void btnOpenWith_DropDownOpened(object sender, EventArgs e) {
      var mnu = new ShellContextMenu(this._ShellListView, false);

      var controlPos = btnOpenWith.TransformToAncestor(Application.Current.MainWindow).Transform(new WIN.Point(0, 0));
      var tempPoint = PointToScreen(new WIN.Point(controlPos.X, controlPos.Y));
      mnu.ShowContextMenu(new System.Drawing.Point((int)tempPoint.X, (int)tempPoint.Y + (int)btnOpenWith.ActualHeight), 1);
      btnOpenWith.IsDropDownOpen = false;
    }
All Usage Examples Of BExplorer.Shell.ShellContextMenu::ShowContextMenu