User-Defined Protocol Registration and program example (C #)

Source: Internet
Author: User

Here, we will add the "aricc" protocol as an example.

I. First, write a program that supports the aricc ProtocolProgram. Let's use C # To write a sample program.

1. Create a Windows application.

2. Add a Textbox Control to the form.

3. Modify form. CSCodeAs follows:

Public   Partial   Class Form1: Form
{
Public   String CMD;
Public Form1 ()
{
Initializecomponent ();
}

Private VoidForm1_load (ObjectSender, eventargs E)
{
Textbox1.text= This. CMD;
}

}

4. Modify the main entry function in program. CS.

Static   Void Main ( String [] ARGs)
{
Application. enablevisualstyles ();
Application. setcompatibletextrenderingdefault ( False );
Form1 mainform =   New Form1 ();
If (ARGs. Length >   0 )
{
Mainform. cmd = ARGs [ 0 ];
}
Application. Run (mainform );
}

PS: the above purpose is to allow the winform program to support command line parameters. To more intuitively see the test results, we display the received parameters in a textbox in the form load event. That's all.

Assume that the program we generated is aricc.exe. It will be used later.

2. register the custom protocol to be used in the registry. Here, we will add the "aricc" protocol as an example.

1. Add aricc under hkey_classes_root.

2. Modify the "(default)" key value under aricc to "url: custom protocol ". You can write this part on your own.

3. Add a key value "URL protocol" under aricc.

4. Create a new item "shell" under aricc"

5. Create an item "open" under shell"

6. Create a new item "command" under the open item"

7. Modify the default key value of the command item to "C: \ path \ aricc.exe" "% 1"

The custom protocol has been registered.

Iii. Test.

1. Open the inventory, input the following code, and save it as test.html.

< A Href = "Aricc: // testcommandline" > Click here to start the program </ A >

 

2. Double-click the preceding HTML file to open it in the browser.

3. Click the link on the page.

4. You find that the program you just wrote is running. The textbox displays "aricc: // testcommandline /"

 

 

To Xiaoshi: I hope it will help you. Hoho

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.