回 帖 发 新 帖 刷新版面

主题:如何用C#获取EXX,DLL文件的图标资源

如何用C#获取EXX,DLL文件的图标资源 ?
请知道的大哥指教一下 ̄小弟初学哈

回复列表 (共3个回复)

沙发

知道的大哥们帮帮忙哈

板凳

没人知道吗?

3 楼

求人不如求己,自己通过查msdn搞定了~~嘿嘿分享给大家哈,这是我用C#写的第一个程序哦,希望大家多多支持哈
[System.Runtime.InteropServices.DllImport("shell32")]
            private static extern IntPtr ExtractAssociatedIcon(IntPtr hInst,string lpIconPath,ref int lpiIcon);
        static IntPtr hIcon;

        private void button1_Click(object sender, System.EventArgs e)
        {
            OpenFileDialog file=new OpenFileDialog();
            file.Filter="exe files(*.exe)|*.exe|All files(*.*)|*.*";
            file.Title="请选取资源文件";
            if( textBox1.Text!="")
            {
                if(file.ShowDialog()==System.Windows.Forms.DialogResult.OK && file.FileName.Length>0)
                {
                    strName=file.FileName;
                    hIcon=ExtractAssociatedIcon(this.Handle,strName,ref i);
                    icon=Icon.FromHandle(hIcon);
                    imageList1.Images.Add(icon);
                    listView1.LargeImageList=imageList1;
                    listView1.SmallImageList=imageList1;
                    listView1.StateImageList=imageList1;
                    listView1.Items.Add(textBox1.Text,i);
                    listView1.Items[i].ImageIndex=i;
                    i++;
                    Image image=icon.ToBitmap();
                    pictureBox1.Image=image;
                    this.Icon=icon;
                    strSaveName=textBox1.Text;
                    textBox1.Text="";
                }
            }
            else
            {
                MessageBox.Show("请输入资源名称");
                textBox1.Focus();
            }

        
        }

        private void button2_Click(object sender, System.EventArgs e)
        {
            SaveFileDialog saveFile=new SaveFileDialog();
            saveFile.Filter="ico files(*.ico)|*.ico|bmp files(*.bmp)|*.bmp|jpg files(*.jpg)|*.jpg|All files(*.*)|*.*";
            saveFile.FileName=strSaveName;
            if(saveFile.ShowDialog()==System.Windows.Forms.DialogResult.OK && saveFile.FileName.Length>0 && strName=="")
            {
                
                Image image=icon.ToBitmap();
                image.Save(saveFile.FileName);
            }

        }

我来回复

您尚未登录,请登录后再回复。点此登录或注册