Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

Moze li se napuniti imagelist ikonama iz shell32.dll.U pitanju je c#.

[es] :: .NET :: Moze li se napuniti imagelist ikonama iz shell32.dll.U pitanju je c#.

[ Pregleda: 1517 | Odgovora: 2 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

pals
Aleksandar Petrović
Slovenija

Član broj: 249834
Poruke: 9
*.cable.telemach.net.

Sajt: https://webalpe.com


Profil

icon Moze li se napuniti imagelist ikonama iz shell32.dll.U pitanju je c#.10.05.2011. u 16:18 - pre 157 meseci
Moze li se napuniti imagelist ikonama iz shell32.dll.U pitanju je c#.
 
Odgovor na temu

pals
Aleksandar Petrović
Slovenija

Član broj: 249834
Poruke: 9
*.cable.telemach.net.

Sajt: https://webalpe.com


Profil

icon Re: Moze li se napuniti imagelist ikonama iz shell32.dll.U pitanju je c#.11.05.2011. u 20:25 - pre 157 meseci
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]
 
Odgovor na temu

Boris B.
Ljubljana

Član broj: 213615
Poruke: 286
*.evj-kabel.net.



+14 Profil

icon Re: Moze li se napuniti imagelist ikonama iz shell32.dll.U pitanju je c#.11.05.2011. u 21:12 - pre 157 meseci
(.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.
if it walks like a duck and quacks like a duck, it could be a dragon doing a duck
impersonation.
 
Odgovor na temu

[es] :: .NET :: Moze li se napuniti imagelist ikonama iz shell32.dll.U pitanju je c#.

[ Pregleda: 1517 | Odgovora: 2 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.