[C#] 抽取exe和dll程序图标 →→→→→进入此内容的聊天室

来自 , 2019-08-08, 写在 C#, 查看 121 次.
URL http://www.code666.cn/view/88fee042
  1.   [System.Runtime.InteropServices.DllImport("shell32.dll")]
  2.       private static extern int ExtractIconEx(string lpszFile, int niconIndex, IntPtr []phiconLarge,IntPtr []phiconSmall, int nIcons);
  3.  
  4.        private IntPtr[] largeIcons, smallIcons ;  //存放大/小图标的指针数组
  5.  
  6.        private string appPath = @"D:\Program Files\Tencent\QQ\Bin\QQ.exe";
  7.  
  8.       //第一步:获取程序中的图标数
  9.      
  10.       int IconCount = ExtractIconEx(appPath, -1, null,null, 0);
  11.    
  12.      //第二步:创建存放大/小图标的空间
  13.  
  14.       largeIcons = new IntPtr[IconCount];
  15.      
  16.       smallIcons = new IntPtr[IconCount];
  17.  
  18.      //第三步:抽取所有的大小图标保存到largeIcons和smallIcons中
  19.      
  20.       ExtractIconEx(appPath, 0, largeIcons,smallIcons, IconCount);
  21.      
  22.      //第四步:显示抽取的图标(推荐使用imageList和listview搭配显示)
  23.  
  24.       for (int i = 0; i < IconCount; i++)
  25.       {
  26.             this.imageList1.Images.Add(Icon.FromHandle(largeIcons[i])); //图标添加进imageList中
  27.  
  28.             ListViewItem lvi = new ListViewItem();
  29.  
  30.             lvi.ImageIndex = i;  //listview子项图标索引项
  31.  
  32.             this.listview1.Items.Add(lvi);
  33.       }
  34.  
  35.       //第五步:保存图标
  36.        
  37.        for (int i = 0; i < this.listview1.Items.Count; i++)
  38.        {
  39.             System.IO.FileStream fs = new System.IO.FileStream(Application.StartupPath +"\\newIcon.png", System.IO.FileMode.Create);
  40.  
  41.             this.imageList1.Images[this.listview1.Items[i].ImageIndex].Save(fs, System.Drawing.Imaging.ImageFormat.Png);
  42.  
  43.             fs.Close();
  44.        }  

回复 "抽取exe和dll程序图标"

这儿你可以回复上面这条便签

captcha