注册文件新图标及关联文件图标(一)

使用RegCreateKey,RegSetValue等修改注册表的API函数设置文件的关联和图标。在注册表中建立如下结构注册键及键值  
  .bar   =   MyApp  
              MyApp   =   My   Application  
                  |    
                    --   DefaultIcon=   myIcon.ico  
                  |  
                    --   Shell  
                              |  
                                ----open  
                                          |  
                                            ------command   =   MyApp.exe   %1  

首先,将注册需要用到的信息封装成FileTypeRegInfo,定义如下:

using System;
using System.Collections.Generic;
using System.Text;

namespace AlterRegeditIcon
{
    public class FileTypeRegInfo
    {
        /// <summary>
        /// 目标类型文件的扩展名.
        /// </summary>
        public string ExtendName;   //".sto"

        /// <summary>
        /// 目标类型文件的描述.
        /// </summary>
        public string Description;

        /// <summary>
        /// 目标类型文件关联的图标.
        /// </summary>
        public string IcoPath;

        /// <summary>
        /// 打开目标文件运行的程序.
        /// </summary>
        public string ExePath;

        public FileTypeRegInfo()
        { }

        public FileTypeRegInfo(string p_strExtendName)
        {
            ExtendName = p_strExtendName;
        }

        /// <summary>
        /// 构造方法.
        /// </summary>
        /// <param name="p_strExtendName"></param>
        /// <param name="p_strIcoPath"></param>
        public FileTypeRegInfo(string p_strExtendName,string p_strIcoPath)
        {
            ExtendName = p_strExtendName;
            IcoPath = p_strIcoPath;
        }
    }

posted on 2008-05-22 17:28  squll201  阅读(1135)  评论(0)    收藏  举报

导航