C# Windows“打开方式”>'上下文菜单行为
可能的重复:
文件类型与应用程序关联(C#)
我正在编写一个 C# Windows 应用程序来可视化和修改“.build”文件(nant 脚本)。我希望用户能够在 Windows 资源管理器中右键单击 .build 文件并选择“打开方式 >”选项允许在我的应用程序中修改文件。
我的程序需要支持什么才能使用此机制? 我的程序可能需要对 Windows 执行什么操作才能启用上下文菜单支持?
我想知道是否有人可以指出我关于这个主题的好文章/教程的方向。
Possible Duplicate:
Filetype association with application (C#)
I'm writing a C# Windows app to visualise and modify '.build' files (nant scripts). I would like the user to be able to right click on a .build file in windows explorer and select the 'Open With >' option to allow the file to be modified in my app.
What does my program need to support in-order to work with this mechanism?
What might my program need to do to Windows to enable context menu support?
I was wondering if anyone could point me in the direction of a good article/tutorial on this subject.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Open With 命令只是将文件的路径作为第一个参数传递给应用程序,因此您需要做的就是
自动将程序放入打开方式列表中,您需要在
HKEY_CLASSES_ROOT\YOUR_EXT 中添加一些注册表项\。 这是一个答案说明如何做到这一点
或者您可以按照正常方式手动将其添加到打开列表中。
The Open With command just passes the path of the file as the first argument to the application so all you need to do is
To automaticly put your program in the open with list you will need to add some reg keys in
HKEY_CLASSES_ROOT\YOUR_EXT\
. Here is a SO answer saying how to do itOr you could just add it by hand to the open with list the normal way.
看一下这篇博文:Shell 扩展 - 上下文菜单。它具有一些用于 Windows shell 上下文菜单的 COM 挂钩的简单“包装器”的代码。将其放入 GAC 中,当您右键单击时,您的菜单将作为右键单击上下文菜单的子菜单包含在内。
至于严格使用“打开方式...”使您的应用程序仅显示它可以打开的文件,这会更容易一些。这些由 Windows 使用注册表中两个位置的注册表项进行管理:
使用 regedit 查看一些现有的密钥,然后使用Registry 类为您想要的扩展创建一个新密钥。
Take a look at this blog post: Shell Extensions - Context Menu. It has code for a simple "wrapper" to some COM hooks to the Windows shell context menu. Put it in the GAC and when you right-click, your menu will be included as a sub-menu of the right-click context menu.
As far as strictly using "Open With..." to make your application show up ONLY for files it can open, that's a little easier. These are managed by Windows using registry keys in two places in the registry:
Take a look at some of the existing ones using regedit, then use the Registry class to create a new key for the extension you want.