I have a file listing in my application and I would like to allow people to right-click on an item and show the Windows Explorer context menu. I'm assuming I would need to use the IContextMenu interface, but I'm not really sure where to start.
我在我的应用程序中有一个文件列表,我想让人们右键单击一个项目并显示Windows资源管理器上下文菜单。我假设我需要使用IContextMenu接口,但我不确定从哪里开始。
3 个解决方案
#1
There's a very good tutorial (albeit in C++) about hosting an IContextMenu on Raymond Chen's blog in 11 parts (in order):
有一个非常好的教程(尽管在C ++中)关于在Raymond Chen的博客上以11个部分(按顺序)托管IContextMenu:
- Initial foray
- Displaying the context menu
- Invocation location
- Key context
- Handling menu messages
- Displaying menu help
- Invoking the default verb
- Optimizing for the default command
- Adding custom commands
- Composite extensions - groundwork
- Composite extensions - composition
显示上下文菜单
处理菜单消息
显示菜单帮助
调用默认动词
优化默认命令
添加自定义命令
复合扩展 - 基础工作
复合扩展 - 组合
#2
I have written a library that might be able to help you. You could use the controls provided by the library, or if you don't want to do that, looking through the code may give you an answer.
我写了一个可以帮助你的图书馆。您可以使用库提供的控件,或者如果您不想这样做,查看代码可能会给您一个答案。
You can find the library at: http://gong-shell.sourceforge.net/
您可以在以下网址找到该图书馆:http://gong-shell.sourceforge.net/
Please let me know if this helped!
如果有帮助,请告诉我!
#3
I found a great Code Project article that encapsulates everything very nicely into one class!
我发现了一篇很棒的Code Project文章,它很好地将所有内容封装到一个类中!
Explorer Shell上下文菜单
It's as easy as the following code snippet:
它就像下面的代码片段一样简单:
// Sample code
ShellContextMenu ctxMnu = new ShellContextMenu();
FileInfo[] arrFI = new FileInfo[1];
arrFI[0] = new FileInfo(this.treeMain.SelectedNode.Tag.ToString());
ctxMnu.ShowContextMenu(arrFI, this.PointToScreen(new Point(e.X, e.Y)));
The only irksome thing is that it takes either an array of FileInfo[] or an array of DirectoryInfo[] although it was VERY easy to modify the source slightly so that it would take an array of FileSystemInfo[]
唯一令人讨厌的事情是,它需要一个FileInfo []数组或一个DirectoryInfo []数组,虽然它很容易稍微修改源代码,因此需要一个FileSystemInfo数组[]
#1
There's a very good tutorial (albeit in C++) about hosting an IContextMenu on Raymond Chen's blog in 11 parts (in order):
有一个非常好的教程(尽管在C ++中)关于在Raymond Chen的博客上以11个部分(按顺序)托管IContextMenu:
- Initial foray
- Displaying the context menu
- Invocation location
- Key context
- Handling menu messages
- Displaying menu help
- Invoking the default verb
- Optimizing for the default command
- Adding custom commands
- Composite extensions - groundwork
- Composite extensions - composition
显示上下文菜单
处理菜单消息
显示菜单帮助
调用默认动词
优化默认命令
添加自定义命令
复合扩展 - 基础工作
复合扩展 - 组合
#2
I have written a library that might be able to help you. You could use the controls provided by the library, or if you don't want to do that, looking through the code may give you an answer.
我写了一个可以帮助你的图书馆。您可以使用库提供的控件,或者如果您不想这样做,查看代码可能会给您一个答案。
You can find the library at: http://gong-shell.sourceforge.net/
您可以在以下网址找到该图书馆:http://gong-shell.sourceforge.net/
Please let me know if this helped!
如果有帮助,请告诉我!
#3
I found a great Code Project article that encapsulates everything very nicely into one class!
我发现了一篇很棒的Code Project文章,它很好地将所有内容封装到一个类中!
Explorer Shell上下文菜单
It's as easy as the following code snippet:
它就像下面的代码片段一样简单:
// Sample code
ShellContextMenu ctxMnu = new ShellContextMenu();
FileInfo[] arrFI = new FileInfo[1];
arrFI[0] = new FileInfo(this.treeMain.SelectedNode.Tag.ToString());
ctxMnu.ShowContextMenu(arrFI, this.PointToScreen(new Point(e.X, e.Y)));
The only irksome thing is that it takes either an array of FileInfo[] or an array of DirectoryInfo[] although it was VERY easy to modify the source slightly so that it would take an array of FileSystemInfo[]
唯一令人讨厌的事情是,它需要一个FileInfo []数组或一个DirectoryInfo []数组,虽然它很容易稍微修改源代码,因此需要一个FileSystemInfo数组[]