欢迎来到天天文库
浏览记录
ID:57645929
大小:21.39 KB
页数:5页
时间:2020-08-30
《C#编程实现关联文件.docx》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、C#自定义文件图标(2009-05-2214:55:33)转载标签:c文件类型图标it分类:C#在我们自己编写的应用中,经常会用自定义类型的文件的来保存与应用相关的数据,如何改变我们的自定义类型的文件的图标?如何双击自定义类型文件的时候启动相应的应用程序了?本文将告诉你如何通过程序来完成这些功能!比如.xcf文件就是XCodeFactory应用程序的项目文件。如果没有向Windows注册表注册该文件类型,那么.xcf文件的图标将是windows的文件默认图标,并且你双击一个a.xcf文件,也不会自动启动XC
2、odeFactory应用程序来加载a.xcf文件。如何使.xcf文件的图标变成我自己喜爱的图标、如何完成像点击.doc文件就自动打开word程序的功能,下面将告诉你解决方案。我们可以通过手动修改注册表来完成上述任务,更好的方式是,通过程序来实现。这样,在安装应用程序时,就可以自动的注册自定义文件类型了。我通过FileTypeRegister静态类来完成这些功能。首先,将注册需要用到的信息封装成FileTypeRegInfo,定义如下:publicclassFileTypeRegInfo{///3、y>///目标类型文件的扩展名///publicstringExtendName;//".xcf"//////目标文件类型说明///publicstringDescription;//"XCodeFactory项目文件"//////目标类型文件关联的图标///publicstringIcoPath;//////打开目标类型文件的应用程序///publicstringExePa4、th;publicFileTypeRegInfo(){}publicFileTypeRegInfo(stringextendName){this.ExtendName=extendName;}}FileTypeRegister类主要是操作注册表中的内容,实现如下://////FileTypeRegister用于注册自定义的文件类型。///zhuweisky2005.08.31///publicclassFileTypeRegister{#regionRegisterFi5、leType//////RegisterFileType使文件类型与对应的图标及应用程序关联起来。///publicstaticvoidRegisterFileType(FileTypeRegInforegInfo){if(RegistryHelper.FileTypeRegistered(regInfo.ExtendName)){return;}stringrelationName=regInfo.ExtendName.Substring(1,regInfo.Exte6、ndName.Length-1).ToUpper()+"_FileType";RegistryKeyfileTypeKey=Registry.ClassesRoot.CreateSubKey(regInfo.ExtendName);fileTypeKey.SetValue("",relationName);fileTypeKey.Close();RegistryKeyrelationKey=Registry.ClassesRoot.CreateSubKey(relationName);relationKey7、.SetValue("",regInfo.Description);RegistryKeyiconKey=relationKey.CreateSubKey("DefaultIcon");iconKey.SetValue("",regInfo.IcoPath);RegistryKeyshellKey=relationKey.CreateSubKey("Shell");RegistryKeyopenKey=shellKey.CreateSubKey("Open");RegistryKeycommandKey=o8、penKey.CreateSubKey("Command");commandKey.SetValue("",regInfo.ExePath+"%1");relationKey.Close();}//////GetFileTypeRegInfo得到指定文件类型关联信息///publicstaticFileTypeRegInfoGetFileTypeRegInfo(stringe
3、y>///目标类型文件的扩展名///publicstringExtendName;//".xcf"//////目标文件类型说明///publicstringDescription;//"XCodeFactory项目文件"//////目标类型文件关联的图标///publicstringIcoPath;//////打开目标类型文件的应用程序///publicstringExePa
4、th;publicFileTypeRegInfo(){}publicFileTypeRegInfo(stringextendName){this.ExtendName=extendName;}}FileTypeRegister类主要是操作注册表中的内容,实现如下://////FileTypeRegister用于注册自定义的文件类型。///zhuweisky2005.08.31///publicclassFileTypeRegister{#regionRegisterFi
5、leType//////RegisterFileType使文件类型与对应的图标及应用程序关联起来。///publicstaticvoidRegisterFileType(FileTypeRegInforegInfo){if(RegistryHelper.FileTypeRegistered(regInfo.ExtendName)){return;}stringrelationName=regInfo.ExtendName.Substring(1,regInfo.Exte
6、ndName.Length-1).ToUpper()+"_FileType";RegistryKeyfileTypeKey=Registry.ClassesRoot.CreateSubKey(regInfo.ExtendName);fileTypeKey.SetValue("",relationName);fileTypeKey.Close();RegistryKeyrelationKey=Registry.ClassesRoot.CreateSubKey(relationName);relationKey
7、.SetValue("",regInfo.Description);RegistryKeyiconKey=relationKey.CreateSubKey("DefaultIcon");iconKey.SetValue("",regInfo.IcoPath);RegistryKeyshellKey=relationKey.CreateSubKey("Shell");RegistryKeyopenKey=shellKey.CreateSubKey("Open");RegistryKeycommandKey=o
8、penKey.CreateSubKey("Command");commandKey.SetValue("",regInfo.ExePath+"%1");relationKey.Close();}//////GetFileTypeRegInfo得到指定文件类型关联信息///publicstaticFileTypeRegInfoGetFileTypeRegInfo(stringe
此文档下载收益归作者所有