Register the file type and associate it with the Program (1)

Source: Internet
Author: User

On windows, different icons are displayed for different file extensions. However, if your program uses a file extension defined by yourself (for example. guo), when windows finds it as "unknown type", a default unknown type icon is displayed, which is neither easy to see nor easy to find your files in a pile of files.

Therefore, this article describes how to use the registry to change the default icon of a file.

 

Take the. guo type as an example:

 

In C #, you only need to execute:

Registry.SetValue(, , );Registry.SetValue(, , );Registry.SetValue(, , ); Registry.SetValue(, , );

You can create a default icon and a default associated program for the. guo file. MyGuo is the alias of. guo.

In command, % 1 indicates the input file name. For example, if you double-click the D: \ bin \ a. guo file, it is equivalent to executing the following command line:

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

In this example, when guo.exe is started, the file path can be obtained through the args parameter in static void Main (string [] args.

After you run the above Code, you will find that the. guo file icon in Explorer has not changed, because you need to restart the Explorer or the computer to take effect. Is there any way to take effect in real time without restarting? Yes, we use the API to implement:

[System.Runtime.InteropServices.DllImport(    SHChangeNotify( wEventId,  uFlags, IntPtr dwItem1, IntPtr dwItem2);

Then add this sentence after the above Code:

SHChangeNotify(, , IntPtr.Zero, IntPtr.Zero);

What do you see?

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.