C# Class BExplorer.Shell.ShellContextMenu

Provides support for displaying the context menu of a shell item.

Use this class to display a context menu for a shell item, either as a popup menu, or as a main menu.

To display a popup menu, simply call ShowContextMenu(...)/> with the parent control and the position at which the menu should be shown.

To display a shell context menu in a Form's main menu, call the Populate method to populate the menu. In addition, you must intercept a number of special messages that will be sent to the menu's parent form. To do this, you must override Form.WndProc like so:

protected override void WndProc(ref Message m) { if ((m_ContextMenu == null) || (!m_ContextMenu.HandleMenuMessage(ref m))) { base.WndProc(ref m); } }

Where m_ContextMenu is the ShellContextMenu being shown.

Standard menu commands can also be invoked from this class, for example InvokeDelete and InvokeRename.
Show file Open project: Gainedge/BetterExplorer Class Usage Examples

Private Properties

Property Type Description
GenerateExplorerBackgroundMenuItems void
GenerateMenuItem void
GenerateMenuItemExecutable void
GenerateSeparator void
GenerateSubmenu void
GetNewContextMenuItems List
Initialize void
InvokeCommand void
RemoveDefaultExplorerItems void
RemoveDuplicatedSeparators void
RemoveShellMenuItems void
TagManagedMenuItems void

Public Methods

Method Description
GetNewContextMenu ( IListItemEx item, IntPtr &iContextMenuPtr, IContextMenu &iContextMenu ) : bool
GetOpenWithContextMenu ( IListItemEx itemArray, IntPtr &iContextMenuPtr, IContextMenu &iContextMenu ) : bool
HandleMenuMessage ( Message &m ) : bool

Handles context menu messages when the ShellContextMenu is displayed on a Form's main menu bar.

To display a shell context menu in a Form's main menu, call the Populate method to populate the menu with the shell item's menu items. In addition, you must intercept a number of special messages that will be sent to the menu's parent form. To do this, you must override Form.WndProc like so:

protected override void WndProc(ref Message m) { if ((m_ContextMenu == null) || (!m_ContextMenu.HandleMenuMessage(ref m))) { base.WndProc(ref m); } }

Where m_ContextMenu is the ShellContextMenu being shown.

Populate ( Menu menu, CMF additionalFlags ) : void

Populates a Menu with the context menu items for a shell item.

If this method is being used to populate a Form's main menu then you need to call HandleMenuMessage in the Form's message handler.

ShellContextMenu ( IListItemEx items, SVGIO svgio = SVGIO.SVGIO_SELECTION, ShellView view = null ) : System

Initializes a new instance of the ShellContextMenu class.

ShellContextMenu ( ShellView shellView, IListItemEx item ) : System

Initializes a new instance of the ShellContextMenu class.

ShellContextMenu ( ShellView shellView, bool Use_GetNewContextMenu ) : System

Initializes a new instance of the ShellContextMenu class.

ShowContextMenu ( Point pos, int type, System.Boolean shouldShow = true ) : int
ShowContextMenu ( Control control, Point pos, CMF aditionalFlags, bool IsOnEmpty = false ) : void

Shows a context menu for a shell item.

Private Methods

Method Description
GenerateExplorerBackgroundMenuItems ( ContextMenu view, ContextMenu mnu, ContextMenu sortMenu, ContextMenu groupMenu ) : void
GenerateMenuItem ( ContextMenu view, String header, int id, bool isRadio = false, uint atPosition ) : void
GenerateMenuItemExecutable ( ContextMenu view, String header, int id ) : void
GenerateSeparator ( ContextMenu view ) : void
GenerateSubmenu ( ContextMenu child, ContextMenu parent, String header ) : void
GetNewContextMenuItems ( ) : List
Initialize ( IListItemEx items ) : void
InvokeCommand ( IntPtr command, Point pt, IntPtr ansiCommand ) : void
RemoveDefaultExplorerItems ( ContextMenu mnu, Control control, MENUITEMINFO &itemInfo ) : void
RemoveDuplicatedSeparators ( ContextMenu mnu ) : void
RemoveShellMenuItems ( Menu menu ) : void
TagManagedMenuItems ( Menu menu, int tag ) : void

Method Details

GetNewContextMenu() public method

public GetNewContextMenu ( IListItemEx item, IntPtr &iContextMenuPtr, IContextMenu &iContextMenu ) : bool
item IListItemEx
iContextMenuPtr System.IntPtr
iContextMenu IContextMenu
return bool

GetOpenWithContextMenu() public method

public GetOpenWithContextMenu ( IListItemEx itemArray, IntPtr &iContextMenuPtr, IContextMenu &iContextMenu ) : bool
itemArray IListItemEx
iContextMenuPtr System.IntPtr
iContextMenu IContextMenu
return bool

HandleMenuMessage() public method

Handles context menu messages when the ShellContextMenu is displayed on a Form's main menu bar.

To display a shell context menu in a Form's main menu, call the Populate method to populate the menu with the shell item's menu items. In addition, you must intercept a number of special messages that will be sent to the menu's parent form. To do this, you must override Form.WndProc like so:

protected override void WndProc(ref Message m) { if ((m_ContextMenu == null) || (!m_ContextMenu.HandleMenuMessage(ref m))) { base.WndProc(ref m); } }

Where m_ContextMenu is the ShellContextMenu being shown.

public HandleMenuMessage ( Message &m ) : bool
m System.Windows.Forms.Message /// The message to handle. ///
return bool

Populate() public method

Populates a Menu with the context menu items for a shell item.
If this method is being used to populate a Form's main menu then you need to call HandleMenuMessage in the Form's message handler.
public Populate ( Menu menu, CMF additionalFlags ) : void
menu System.Windows.Forms.Menu The menu to populate.
additionalFlags CMF
return void

ShellContextMenu() public method

Initializes a new instance of the ShellContextMenu class.
public ShellContextMenu ( IListItemEx items, SVGIO svgio = SVGIO.SVGIO_SELECTION, ShellView view = null ) : System
items IListItemEx /// The items to which the context menu should refer. ///
svgio SVGIO
view ShellView The ShellView the ContextMenu is associated with
return System

ShellContextMenu() public method

Initializes a new instance of the ShellContextMenu class.
public ShellContextMenu ( ShellView shellView, IListItemEx item ) : System
shellView ShellView The ShellView for this context menu
item IListItemEx /// The item to which the context menu should refer. ///
return System

ShellContextMenu() public method

Initializes a new instance of the ShellContextMenu class.
public ShellContextMenu ( ShellView shellView, bool Use_GetNewContextMenu ) : System
shellView ShellView The ShellView the ContextMenu is associated with
Use_GetNewContextMenu bool
return System

ShowContextMenu() public method

public ShowContextMenu ( Point pos, int type, System.Boolean shouldShow = true ) : int
pos Point
type int
shouldShow System.Boolean
return int

ShowContextMenu() public method

Shows a context menu for a shell item.
public ShowContextMenu ( Control control, Point pos, CMF aditionalFlags, bool IsOnEmpty = false ) : void
control System.Windows.Forms.Control /// The parent control. ///
pos Point /// The position on that the menu /// should be displayed at. ///
aditionalFlags CMF
IsOnEmpty bool
return void