C# 获取exe文件中的图标

要用到命名空间:using System.IO;
+展开
-C#

        public Icon[] myicon=new Icon[1000];
        public int currentIndex=0;
        [System.Runtime.InteropServices.DllImport("shell32.dll")]
        private static extern int ExtractIconEx(string lpszFile, int niconIndex, ref IntPtr phiconLarge, ref IntPtr phiconSmall, int nIcons);
//打开exe文件        
        private void button1_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                this.Refresh();
                IntPtr Large, Small;
                int i, nIcons;
                Large = (IntPtr)0;
                Small = (IntPtr)0;
                nIcons = ExtractIconEx(openFileDialog1.FileName, -1, ref Large, ref Small, 1);
                Graphics g = this.CreateGraphics();
                for (i = 0; i < nIcons; i++)
                {
                    ExtractIconEx(openFileDialog1.FileName, i, ref Large, ref Small, 1);
                    myicon[currentIndex] = Icon.FromHandle(Large);
                    g.DrawIcon(myicon[currentIndex], (i / 3) * 40, (i % 3) * 40);
                    currentIndex++;
                }
            }
        }
//保存icon图标
        private void button2_Click(object sender, EventArgs e)
        {
            FileStream fs;
            for (int j = 0; j < currentIndex; j++)
            {
                fs = new FileStream("c:\\"+j.ToString()+".ico",FileMode.Create,FileAccess .ReadWrite);
                myicon[j].Save(fs);
                fs.Close();
            }
            MessageBox.Show ("保存成功!");
        } 


http://www.cnblogs.com/tuyile006/archive/2006/12/25/602818.html

加支付宝好友偷能量挖...


评论(0)网络
阅读(118)喜欢(0)Asp.Net/C#/WCF