通过双击创建用于打开文件的应用程序。 [英] Creating an application for opening a file by double clicking on it.

查看:164
本文介绍了通过双击创建用于打开文件的应用程序。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我想要一个文件(带有自定义扩展名,例如:.va),当我双击它时,我的应用程序就会打开它。



我怎么能用vb.net做这个,



你可以给我一些例子。 ....



谢谢

Srinivas

Hi guys,

I want a file (with custom extension eg: .va) to be opened in my application when i double click on it..

how can i do this with vb.net,

can u give me some examples of it.....

Thank you
Srinivas

推荐答案

也许你意味着点击某个管理器中的文件,如Windows资源管理器;实际上,使用Shell API的任何管理器或其他应用程序都将使用系统注册表中规定的相关信息打开您的应用程序,该信息称为注册文件类型。通常,这是由安装程序完成的(有充分理由:最终,您需要从系统中删除此信息),但您可以通过使用注册表直接执行此操作。



首先,您需要开发应用程序来处理命令行。命令行传递给您的入口点函数( Main ): http://en.wikipedia.org/wiki/Main_function#C.23 [ ^ ]。



此外,命令行参数可通过 System.Environment访问。 GetCommandLineArgs System.Environment.CommandLine (未解析):

http://msdn.microsoft.com/en-us/library/system.environment.getcommandlineargs(v= vs.110).aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/system.environment.command line(v = vs.110).aspx [ ^ ]。



我的CodeProject文章提供了一种非常方便的解析命令行参数的方法你可以在你的VB.NET应用程序中使用;本文引用了另一个好的实用程序:

基于枚举命令行实用程序 [ ^ ]。



在您的申请中,您将获得一个完整的文件名;然后你可以按照你想要的方式使用它。该参数将从Windows Shell传递给您。要实现这一点,您需要注册一些文件类型。例如,请参阅此CodeProject文章: VB.NET中的文件关联 [ ^ ]。



-SA
Probably you mean clicking on a file in some manager like Windows Explorer; actually any manager or other application using Shell API will open your application using the related information prescribed in the system registry, which is called "register a file type". Normally, this is done by an installer (by a good reason: eventually, you will need to remove this information from your system), but you can do it directly by manipulating with the registry.

First of all, you need to develop your application to handle the command line. Command line is passed to your entry-point function (Main): http://en.wikipedia.org/wiki/Main_function#C.23[^].

Also, the command line parameters are accessible via System.Environment.GetCommandLineArgs or System.Environment.CommandLine (unparsed):
http://msdn.microsoft.com/en-us/library/system.environment.getcommandlineargs(v=vs.110).aspx[^],
http://msdn.microsoft.com/en-us/library/system.environment.commandline(v=vs.110).aspx[^].

My CodeProject article offers a very convenient way of parsing command line parameters which you can use in your VB.NET application; another good utility is referenced in this article:
Enumeration-based Command Line Utility[^].

In your application, you will get a full file name; then you can use it the way you want. The parameter will be passed to you from the Windows Shell. To achieve that, you will need to register some file type(s). See, for example, this CodeProject article: File Association in VB.NET[^].

—SA


这篇关于通过双击创建用于打开文件的应用程序。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆