Ejemplo n.º 1
0
        /// <summary>
        /// Gets a System.Drawing.Icon that represents RT_GROUP_ICON at the givin index from the executable module.
        /// </summary>
        /// <param name="index">The index of the RT_GROUP_ICON in the executable module.</param>
        /// <returns>Returns System.Drawing.Icon.</returns>
        private Icon GetIconFromLib(int index)
        {
            byte[] resourceData = GetResourceData(this.ModuleHandle, this.IconNames[index], ResourceTypes.RT_GROUP_ICON);
            //Convert the resouce into an .ico file image.
            using (MemoryStream inputStream = new MemoryStream(resourceData))
                using (MemoryStream destStream = new MemoryStream())
                {
                    //Read the GroupIconDir header.
                    GroupIconDir grpDir = inputStream.Read <GroupIconDir>();

                    int numEntries      = grpDir.Count;
                    int iconImageOffset = IconInfo.SizeOfIconDir + numEntries * IconInfo.SizeOfIconDirEntry;

                    destStream.Write <IconDir>(grpDir.ToIconDir());
                    for (int i = 0; i < numEntries; i++)
                    {
                        //Read the GroupIconDirEntry.
                        GroupIconDirEntry grpEntry = inputStream.Read <GroupIconDirEntry>();

                        //Write the IconDirEntry.
                        destStream.Seek(IconInfo.SizeOfIconDir + i * IconInfo.SizeOfIconDirEntry, SeekOrigin.Begin);
                        destStream.Write <IconDirEntry>(grpEntry.ToIconDirEntry(iconImageOffset));

                        //Get the icon image raw data and write it to the stream.
                        byte[] imgBuf = GetResourceData(this.ModuleHandle, grpEntry.ID, ResourceTypes.RT_ICON);
                        destStream.Seek(iconImageOffset, SeekOrigin.Begin);
                        destStream.Write(imgBuf, 0, imgBuf.Length);

                        //Append the iconImageOffset.
                        iconImageOffset += imgBuf.Length;
                    }
                    destStream.Seek(0, SeekOrigin.Begin);
                    return(new Icon(destStream));
                }
        }
Ejemplo n.º 2
0
        public WORD Count;      // How many images?

        public GroupIconDir ToGroupIconDir()
        {
            GroupIconDir grpDir = new GroupIconDir();
            grpDir.Reserved = this.Reserved;
            grpDir.Type = this.Type;
            grpDir.Count = this.Count;
            return grpDir;
        }
Ejemplo n.º 3
0
        public WORD Count;      // How many images?

        public GroupIconDir ToGroupIconDir()
        {
            GroupIconDir grpDir = new GroupIconDir();

            grpDir.Reserved = this.Reserved;
            grpDir.Type     = this.Type;
            grpDir.Count    = this.Count;
            return(grpDir);
        }
Ejemplo n.º 4
0
        public WORD Count;      // How many images?

        public GroupIconDir ToGroupIconDir()
        {
            var grpDir = new GroupIconDir();

            grpDir.Reserved = Reserved;
            grpDir.Type     = Type;
            grpDir.Count    = Count;
            return(grpDir);
        }