Register the file type and associate the program (3)

Source: Internet
Author: User

Double-click a txt file to open it in notepad, because the txt file is associated with the Notepad program.

If you want to customize the file type, you can directly call your program and open it by double-clicking it? OK. First, we can find the first issue and see the following line of code:

Registry.SetValue(, , );

When you double-click the D: \ bin \ a. guo file, it is equivalent to executing the command line:

D:\bin\Guo.exe “D:\bin\a.guo”

D: \ bin \ a.guopassed the command line to the guo.exe program.

But how does the exe program accept this command line parameter?

In VS, If you create a new "console Program", there will be such a method in the automatically created Program. cs.

  Main([] args)

Args is the command line parameter. In the following example, args [0] is "D: \ bin \ a. guo ";

However, when you create a "Windows form application", you will find that the Main in Program is like this.

  Main()

Args is gone! Don't worry. Just change Main () to Main (string [] args.

In addition, args is not null here. If there is no parameter, It is args. Length = 0;

 

Sometimes, our program imposes format restrictions on command line parameters. For example, it may be like this to indicate the input file:

D:\bin\Guo.exe –i “D:\bin\a.guo”

This method of using a "key-Value Pair" as a parameter is very common in practice, because it does not need to limit the order of parameters, it is also easy to remember; for such a form, you only need to change the above command content to "D: \ bin \ Guo.exe-I \" % 1;

However, there are two scenarios for this method: drag the file to the guo.exe file and release it. In the open-ended documentation, select to use the guo.exe file to open it;

In both cases, Windows will execute the following command line to open the exe:

D: \ bin \ Guo.exe "file path"

The-I parameter is not available. It depends on your own.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.