ShellBrowser Delphi Components Documentation
ContentsIndexHome
PreviousUpNext
ShellBrowser.TShellBrowser.ShowContextMenu

Shows the context menu for files or folders.

Syntax
Pascal
function ShowContextMenu(const lppt: TPoint; M: TPopupMenu = nil; ShellMenuAnchor: TMenuItem = nil; Sender: IShellCommandInvokable = nil): String; overload;
Parameters 
Description 
const lppt: TPoint 
Use ShowContextMenu to show the context menu for the current object at position lppt. This is the absolute position on the windows screen. You can use the ClientToScreen method of Delphis VCL components to get the absolute coordinates.  
M: TPopupMenu = nil 
If M is not nil, the given Delphi popup menu will appear at the end of the explorer context menu. See InvokeContextMenuCommand for more information.  
ShellMenuAnchor: TMenuItem = nil 
Optional: A menu item after that the Shell context menu should be inserted. If you want to show a the Shell context menu as submenu, add a signle menu item as submenu and set its Visible property to False. You may then use this menu item as anchor for the Shell context menu. The default value is nil.  
Sender: IShellCommandInvokable = nil 
The sender that implements the OnBeforeShellCommand event. 

The function returns the verb of the executed command (e.g. 'open', 'properties', 'delete') or the empty string if the user didn't select a command.

If you want to show the context menu for multiple objects, you must add the names of these objects to MultiObjects. ShowContextMenu will use the names provided in MultiObjects, if this list is not empty.

You can control if the shell context menu should be added above or below the supplied TPopupMenu using the property ShowContextMenuOnTop. It is not recommended to use owner-drawn VCL popup menus here as they force the Windows Shelll context menu into an unthemed Windows 2000 comptibility mode.

The following example will react on a right click of the user in a tree view. The full path of the folder is stored in the data property of the TTreeNode. If you are using Delphi 3, you should set the RightClickSelect property of your TTreeView to true.

procedure TMainForm.TreeViewMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var Node: TTreeNode;
begin
  if Button <> mbRight then exit;
  Node := TreeView.GetNodeAt(X,Y);
  if not Assigned(Node) then exit; // No Item hit
  ShellBrowser.ObjectName := PChar(Node.Data);
  ShellBrowser.ShowContextMenu(TreeView.ClientToScreen(Point(x,y)), nil);
end;