8

I'm trying to display standard file/directory context menu in WinForms application - I'd like to enable the user to do things with files in my application as he could in Explorer.

There should be two options

  • popup the context menu with some system call
  • read everything from the system context menu and insert it into my context menu

Could you please point me in the right direction? Thanks

Axarydax
  • 16,353
  • 21
  • 92
  • 151

2 Answers2

8

I have written a .NET library to allow this. You can find it here:

http://gong-shell.sourceforge.net/

The class you're looking for is ShellContextMenu within that library.

Grokys
  • 16,228
  • 14
  • 69
  • 101
  • Groky that library that you created is amazing. I do not know that much about win forms so I been having a hard time trying to see how you implemented the context menu. I need to implement that in wpf. I am sure that it will be essay to implement it on wpf once I know how to do it in win forms. – Tono Nam Oct 27 '11 at 15:56
  • Also I don't need it to look like the file dialog. I just have a container on my wpf application that displays files (icons with labels) and I will like to enable users to see the same context menu that they see when they right click on that file on windows explorer. – Tono Nam Oct 27 '11 at 15:59
  • @TonoNam: unfortunately I didn't implement the context menu - I just used the Windows Shell API to display the context menu used by Explorer. I have no idea how you'd implement it in WPF, or even if such a thing would be possible, sorry. – Grokys Oct 27 '11 at 18:27
5

This may prove to be very challenging, so I propose two solutions:

  1. (Easy) Using the library that Groky suggested, do what is done in FolderSizes. The Explorer context menu is shown as a sub-context-menu. You can simulate this by displaying the explorer menu when the "Explorer Operation" item is hovered.

    enter image description here

  2. (Hard) If that is insufficient, you can go all the way and get the menu items from the shell, and create your own menu. This CodeProject article ( http://www.codeproject.com/KB/miscctrl/FileBrowser.aspx ) goes through the process of enumerating and invoking shell commands for a specific shell object, and how to enumerate submenus.

Kevin McCormick
  • 2,358
  • 20
  • 20