Showing windows (file/directory) context menu in c# winforms application

陌路散爱 提交于 2019-12-18 05:56:38

问题


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


回答1:


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.




回答2:


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.

  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.



来源:https://stackoverflow.com/questions/2583946/showing-windows-file-directory-context-menu-in-c-sharp-winforms-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!