0

I write my own file explorer in SFML. I will create my own popup menu, but I think some people would like to use also the default options for items (folders, files, shortcuts). So one of the options in my popup menu will be the "Open default context menu here". But I don't know how to do that. I did some research and I read a lot of threads, articles, WinAPI documentation and other resources. I tried to simulate right-click in another window, I tried to simulate the Shift+F10 shortcut. Now I fight with menus. But I still have no results. I saw something like this in the file explorer that I used to. There must be a solution to this.

I found this Show system menu from another process (using WinForms, c#) But this activates standard windows menu (alt+space) but I want right-click menu (Shift+F10).

1 Answers1

0

You can't popup a file/folder's default right-click menu itself. But you can create your own menu and populate it with menu items relating to the file/folder, and invoke those items when clicked, by using the file/folder's own IContextMenu interface.

In a nutshell, you obtain the IContextMenu for the desired file/folder, such as via IShellFolder::GetUIObjectOf() or IShellItem::BindToHandler(), and then you use the IContextMenu::QueryContextMenu() method to populate your menu with items, and the IContextMenu::InvokeCommand() method to invoke commands from those items.

Raymond Chen wrote a series of articles on this very subject, which shows just how complex this task can be. There is too much information to post here.

How to host an IContextMenu, part 1 – Initial foray

How to host an IContextMenu, part 2 – Displaying the context menu

How to host an IContextMenu, part 3 – Invocation location

How to host an IContextMenu, part 4 – Key context

How to host an IContextMenu, part 5 – Handling menu messages

How to host an IContextMenu, part 6 – Displaying menu help

How to host an IContextMenu, part 7 – Invoking the default verb

How to host an IContextMenu, part 8 – Optimizing for the default command

How to host an IContextMenu, part 9 – Adding custom commands

How to host an IContextMenu, part 10 – Composite extensions – groundwork

How to host an IContextMenu, part 11 – Composite extensions – composition

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770