[ pals @ 10.05.2011. 16:18 ] @
Moze li se napuniti imagelist ikonama iz shell32.dll.U pitanju je c#. |
[ pals @ 10.05.2011. 16:18 ] @
[ pals @ 11.05.2011. 20:25 ] @
Evo kod koji prikazuje ikone iz datoteke shell32.dll.Klikom na ikonu prikazuje redni broj.
Code (csharp): using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Runtime.InteropServices; namespace WindowsApplication3 { public partial class Form1 : Form { public Label labi; public Form1() { InitializeComponent(); } [DllImport("Shell32.dll")] public extern static int ExtractIconEx(string libName, int iconIndex, IntPtr[] largeIcon, IntPtr[] smallIcon, int nIcons); private void Form1_Load(object sender, EventArgs e) { this.Text = "Prikaz ikona iz datoteke shell32.dll"; labi = new Label(); labi.Size = new Size(285, 23); labi.Location = new Point(32, 42); labi.Name = "label1"; labi.Font = new Font("Arial", 10, FontStyle.Bold); this.Controls.Add(labi); this.AutoScroll = true; int numIcons = 220; IntPtr[] largeIcon = new IntPtr[numIcons]; IntPtr[] smallIcon = new IntPtr[numIcons]; ExtractIconEx("shell32.dll",0, largeIcon, smallIcon, numIcons); //Icon largeIico = Icon.FromHandle(largeIcon[1]); //Icon smallIco = Icon.FromHandle(smallIcon[3]); int brojac=0; int lok1=30; int lok2 = 30; for (int i = 0; i < 220; i++) { brojac++; lok2 = lok2 + 50; PictureBox pb = new PictureBox(); pb.Name = brojac.ToString(); pb.Location = new Point(lok1, lok2 ); if (brojac % 10 == 0) { lok1 = lok1 + 50; lok2 = 30; } pb.Size = new Size(50, 50); pb.Image = Icon.FromHandle(largeIcon[i]).ToBitmap(); pb.Cursor = Cursors.Hand; pb.Click+=new EventHandler(pb_Click); this.Controls.Add(pb); } Label lab = new Label(); lab.Size = new Size(285, 23); lab.Location = new Point(32, 22); lab.Name ="label1"; lab.Font = new Font("Arial", 10, FontStyle.Bold); this.Controls.Add(lab); lab.Text ="Broj prikazanih ikona - " +brojac.ToString(); } private void pb_Click(object sender, EventArgs e) { PictureBox pb = (PictureBox)sender; labi.Text ="Redni broj ikone : "+ pb.Name.ToString(); } } } [Ovu poruku je menjao Shadowed dana 11.05.2011. u 22:43 GMT+1] [ Boris B. @ 11.05.2011. 21:12 ] @
(.Net 4)
Code (csharp): [DllImport("shell32.dll", CharSet = CharSet.Auto)] private static extern uint ExtractIconEx(string szFileName, int nIconIndex, IntPtr[] phiconLarge, IntPtr[] phiconSmall, uint nIcons); [DllImport("user32.dll")] private static extern void DestroyIcon(IntPtr hIcon); public static Tuple<List<Bitmap>, List<Bitmap>> GetShellIcons() { var count = ExtractIconEx("shell32.dll", -1, null, null, 0); var largeHIcons = new IntPtr[count]; var smallHIcons = new IntPtr[count]; ExtractIconEx("shell32.dll", 0, largeHIcons, smallHIcons, count); var largeIcons = largeHIcons.Select(Icon.FromHandle).Select(i => i.ToBitmap()).ToList(); var smallIcons = smallHIcons.Select(Icon.FromHandle).Select(i => i.ToBitmap()).ToList(); largeHIcons.ToList().ForEach(DestroyIcon); smallHIcons.ToList().ForEach(DestroyIcon); return new Tuple<List<Bitmap>, List<Bitmap>>(smallIcons, largeIcons); } Ako koristiš .Net 3.5 zameni Tuple sa svojom klasom. Edit: A, vidim da si se snašao i sam. Copyright (C) 2001-2025 by www.elitesecurity.org. All rights reserved.
|