GetIcons:C#提取应用程序的图标资源

来源:互联网 发布:三星集团的成功 知乎 编辑:程序博客网 时间:2024/06/12 22:09

在写C#窗口程序时,看厌了默认的图标,想更换下图标,可是电脑中的图标文件(.ico)很少。于是,想到写个程序来提取其他程序中的图标资源。

【网通】点击这里下载全部源程序     【电信、网通】点击这里下载源程序

【下载说明】
1、单击上面这个地址,打开下载页面。
2、点普通下载--等待30秒--点“下载”按钮--保存

部分源程序:

public static void ExtractIconFromExe(string file,bool large)        {            unsafe            {                uint readIconCount = 0;                IntPtr[] hDummy  = new IntPtr[]{IntPtr.Zero};                IntPtr[] hIconEx = new IntPtr[]{IntPtr.Zero};                try                {                                        readIconCount = ExtractIconEx(file,-1,hIconEx,hDummy,1);                    //                    MessageBox.Show(readIconCount.ToString());                    if(readIconCount > 0)                    {                        if(large){                            LargeIcons.Clear();                        }else{                            SmallIcons.Clear();                        }                                                for(int i=0;i<readIconCount;i++){//                            MessageBox.Show(i.ToString()+"\t"+readIconCount.ToString());                            ExtractIconEx(file,i,hIconEx,hDummy,(uint)1);                            if(large){                                if(hIconEx[0]!=IntPtr.Zero){                                    LargeIcons.Add((Icon)Icon.FromHandle(hIconEx[0]).Clone());                                }else{                                    MessageBox.Show("Can not extract icon "+i.ToString());                                }                            }else{                                if(hDummy[0]!=IntPtr.Zero){                                    SmallIcons.Add((Icon)Icon.FromHandle(hDummy[0]).Clone());                                }else{                                    MessageBox.Show("Can not extract icon "+i.ToString());                                }                            }                            //                            MessageBox.Show("Extract Icon "+i.ToString());                        }                                                return;                    }                }                catch(Exception   ex)                {                    throw new ApplicationException( "Could not extract icon ", ex);                }            }        }

【更多阅读】

  1. [原]PjConvertImageFormat:用FreeImage.NET写的一个35种图像格式转换程序
  2. [原]ManageStartUpApps:C#操作注册表来读取和修改开机启动项
  3. [原]QQHelper:QQ大家来找茬 辅助工具 外挂
  4. [原]PjConvertImageFormat:用FreeImage.NET写的一个35种图像格式转换程序
  5. [原]Baidu:C#利用百度来搜索网页、图片、视频等等
  6. [原]ManageApps:C#读取Windows系统中的已经安装的程序并卸载软件
  7. [原]ManageStartUpApps:C#操作注册表来读取和修改开机启动项
  8. [原]PjCleanSystemTrash:C#清除系统盘垃圾
  9. [原]Cls_Ini.cls:VB写的操作ini配置文件的类
  10. [原]BinaryEditor:用ListView实现编辑二进制文件

原创粉丝点击