Beispiel #1
0
        private void PopulateWin32Types(Boolean sortByName)
        {
            __typeKnown.Items.Clear();

            List <Pair <String, Win32ResourceType> > items = new List <Pair <String, Win32ResourceType> >();

            Int32[] vals = (Int32[])Enum.GetValues(typeof(Win32ResourceType));
            foreach (Int32 v in vals)
            {
                if (v <= 0)
                {
                    continue;
                }

                Win32ResourceType val = (Win32ResourceType)v;

                String name = ResourceTypeIdentifier.GetTypeFriendlyName(v) + " (" + v.ToString(CultureInfo.InvariantCulture) + ')';

                Pair <String, Win32ResourceType> item = new Pair <String, Win32ResourceType>(name, val);

                items.Add(item);
            }

            if (sortByName)
            {
                items.Sort((x, y) => x.X.CompareTo(y.X));
            }
            else
            {
                items.Sort((x, y) => x.Y.CompareTo(y.Y));
            }

            foreach (Pair <String, Win32ResourceType> item in items)
            {
                __typeKnown.Items.Add(item);
            }
        }
Beispiel #2
0
        private IconCursorImageResourceDataFactory GetImageFactory()
        {
            if (_imgFactory != null)
            {
                return(_imgFactory);
            }

            Win32ResourceType desired = Type == IconType.Icon ? Win32ResourceType.IconImage : Win32ResourceType.CursorImage;

            ResourceTypeIdentifier typeId = new ResourceTypeIdentifier(desired);

            ResourceDataFactory[] factories = ResourceDataFactory.GetFactoriesForType(typeId);

            foreach (ResourceDataFactory f in factories)
            {
                IconCursorImageResourceDataFactory icif = f as IconCursorImageResourceDataFactory;
                if (icif != null)
                {
                    return(_imgFactory = icif);
                }
            }

            return(_imgFactory);
        }
Beispiel #3
0
        public static ResIconDir FromResource(ResourceLang lang, Byte[] rawBytes)
        {
            Int32 sizeOfIconDir = Marshal.SizeOf(typeof(IconDirectory));
            Int32 sizeOfDirEntr = Marshal.SizeOf(typeof(ResIconDirectoryEntry));

            // the data in here is an ICONDIR structure

            IntPtr p = Marshal.AllocHGlobal(rawBytes.Length);

            Marshal.Copy(rawBytes, 0, p, rawBytes.Length);

            // this could be vastly simplified by correctly marshaling the member array of IconDirectory
            // but that's a can of worms, I'd rather not
            IconDirectory dir = (IconDirectory)Marshal.PtrToStructure(p, typeof(IconDirectory));

            Marshal.FreeHGlobal(p);

            if (dir.wType != 1 && dir.wType != 2)
            {
                throw new InvalidOperationException("Provided rawData is not an icon or cursor");
            }

            ResIconDirectoryEntry[] subImages = new ResIconDirectoryEntry[dir.wCount];

            for (int i = 0; i < dir.wCount; i++)
            {
                Int32 byteOffset = sizeOfIconDir + sizeOfDirEntr * i;

                p = Marshal.AllocHGlobal(sizeOfDirEntr);
                Marshal.Copy(rawBytes, byteOffset, p, sizeOfDirEntr);

                ResIconDirectoryEntry img = (ResIconDirectoryEntry)Marshal.PtrToStructure(p, typeof(ResIconDirectoryEntry));

                subImages[i] = img;
            }

            ResIconDir retval = new ResIconDir(dir.wType == 1, lang.LanguageId, lang.Name.Type.Source);

            // then we might be able to get the resourcedata for the subimages to include in the directory

            // find the Icon Image resource type
            ResourceType      imageType = null;
            Win32ResourceType desired   = dir.wType == 1 ? Win32ResourceType.IconImage : Win32ResourceType.CursorImage;

            foreach (ResourceType type in lang.Name.Type.Source.AllTypes)
            {
                if (type.Identifier.KnownType == desired)
                {
                    imageType = type;
                    break;
                }
            }

            if (imageType != null)
            {
                foreach (ResIconDirectoryEntry img in subImages)
                {
                    IconCursorImageResourceData rd = GetDataFromWid(imageType, lang, img.wId);

                    Size dimensions = new Size(img.bWidth == 0 ? 256 : img.bWidth, img.bHeight == 0 ? 256 : img.bHeight);
                    // cursors might have Height == 0, so it should copy the width rather than being set to 256

                    retval.Members.Add(new IconDirectoryMember(rd, dimensions, img.bColorCount, img.bReserved, img.wPlanes, img.wBitCount, img.dwBytesInRes));
                }
            }

            return(retval);
        }
Beispiel #4
0
 internal Win32Resource(Win32ResourceType type, int name, int language)
 {
     this.type     = new NameOrId((int)type);
     this.name     = new NameOrId(name);
     this.language = language;
 }
Beispiel #5
0
	internal Win32Resource (Win32ResourceType type, int name, int language) {
		this.type = new NameOrId ((int)type);
		this.name = new NameOrId (name);
		this.language = language;
	}
Beispiel #6
0
 public Win32Resources(Win32ResourceType resourceType, Win32Resource[] resouces)
 {
     ResourceType = resourceType;
     Resouces     = resouces;
 }