示例#1
0
        public static Icon GetIcon(int index, bool small)
        {
            IntPtr iconPtr;

            if (small)
            {
                iconPtr = ShellAPI.ImageList_GetIcon(smallImageListHandle, index, ShellAPI.ILD.NORMAL);
            }
            else
            {
                iconPtr = ShellAPI.ImageList_GetIcon(largeImageListHandle, index, ShellAPI.ILD.NORMAL);
            }

            if (iconPtr != IntPtr.Zero)
            {
                Icon icon   = Icon.FromHandle(iconPtr);
                Icon retVal = (Icon)icon.Clone();
                ShellAPI.DestroyIcon(iconPtr);
                return(retVal);
            }
            else
            {
                return(null);
            }
        }