Esempio n. 1
0
        protected virtual bool LoadData(IntPtr hMod, NativeMethods.FileRecord Record)
        {
            IntPtr hRes = NativeMethods.FindResource(hMod, (IntPtr)Record.nID, (IntPtr)NativeMethods.RT_CURSOR);

            if (hRes == IntPtr.Zero)
            {
                return(false);
            }

            uint   size = NativeMethods.SizeofResource(hMod, hRes);
            IntPtr pt   = NativeMethods.LoadResource(hMod, hRes);

            Record.Data = new byte[size];
            Marshal.Copy(pt, Record.Data, 0, (int)size);

            Record.HotspotX = BitConverter.ToUInt16(Record.Data, 0);
            Record.HotspotY = BitConverter.ToUInt16(Record.Data, 2);

            return(true);
        }
Esempio n. 2
0
        /// <summary>
        ///     Load the cursor directory with images.
        /// </summary>
        protected virtual bool LoadDirectory(IntPtr hMod, out NativeMethods.FileHeader Header, out List <NativeMethods.FileRecord> RecordList)
        {
            IntPtr hResDir = NativeMethods.FindResource(hMod, (IntPtr)ResourceID, (IntPtr)NativeMethods.RT_GROUP_CURSOR);

            if (hResDir == IntPtr.Zero)
            {
                Header     = null;
                RecordList = null;
                return(false);
            }

            uint   size = NativeMethods.SizeofResource(hMod, hResDir);
            IntPtr pt   = NativeMethods.LoadResource(hMod, hResDir);

            byte[] bPtr = new byte[size];
            Marshal.Copy(pt, bPtr, 0, (int)size);

            if (size < 6)
            {
                Header     = null;
                RecordList = null;
                return(false);
            }

            Header            = new NativeMethods.FileHeader();
            Header.Reserved   = BitConverter.ToInt16(bPtr, 0);
            Header.Type       = BitConverter.ToInt16(bPtr, 2);
            Header.ImageCount = BitConverter.ToInt16(bPtr, 4);

            List <NativeMethods.FileRecord> TempRecordList = new List <NativeMethods.FileRecord>();

            NativeMethods.FileRecord GoodSizedImage = null;

            for (short i = 0; i < Header.ImageCount; i++)
            {
                int Offset = (i * 14) + 6;

                NativeMethods.FileRecord Record = new NativeMethods.FileRecord();
                Record.bWidth  = bPtr[Offset + 0];
                Record.bHeight = Record.bWidth;
                short wBitCount = BitConverter.ToInt16(bPtr, Offset + 6);
                Record.bColorCount = (byte)Math.Pow(2, wBitCount);
                Record.bReserved   = 0;
                Record.nID         = BitConverter.ToUInt16(bPtr, Offset + 12);

                TempRecordList.Add(Record);
                if (Record.bWidth == PreferredSize)
                {
                    GoodSizedImage = Record;
                }
            }

            RecordList = new List <NativeMethods.FileRecord>();
            if (GoodSizedImage != null)
            {
                RecordList.Add(GoodSizedImage);
            }
            else
            {
                RecordList.AddRange(TempRecordList);
            }

            return(true);
        }
Esempio n. 3
0
        /// <summary>
        /// Load the cursor directory with images.
        /// </summary>
        /// <param name="hMod">Handle of the resource file.</param>
        /// <param name="header">Header of the resource file.</param>
        /// <param name="recordList">List of record.</param>
        /// <returns>True if successful; otherwise, false.</returns>
        protected virtual bool LoadDirectory(IntPtr hMod, out NativeMethods.FileHeader header, out List <NativeMethods.FileRecord> recordList)
        {
            IntPtr hResDir = NativeMethods.FindResource(hMod, (IntPtr)ResourceID, (IntPtr)NativeMethods.RT_GROUP_CURSOR);

            if (hResDir == IntPtr.Zero)
            {
                Contract.Unused(out header);
                Contract.Unused(out recordList);
                return(false);
            }

            uint size = NativeMethods.SizeofResource(hMod, hResDir);

            if (size < 6)
            {
                Contract.Unused(out header);
                Contract.Unused(out recordList);
                return(false);
            }

            IntPtr pt = NativeMethods.LoadResource(hMod, hResDir);

            byte[] bPtr = new byte[size];
            Marshal.Copy(pt, bPtr, 0, (int)size);

            header = new NativeMethods.FileHeader
            {
                Reserved   = BitConverter.ToInt16(bPtr, 0),
                Type       = BitConverter.ToInt16(bPtr, 2),
                ImageCount = BitConverter.ToInt16(bPtr, 4),
            };

            recordList = new List <NativeMethods.FileRecord>();
            List <NativeMethods.FileRecord> TempRecordList = new List <NativeMethods.FileRecord>();
            bool IsGoodSizedImageAdded = false;

            for (short i = 0; i < header.ImageCount; i++)
            {
                int Offset = (i * 14) + 6;

                NativeMethods.FileRecord Record = new NativeMethods.FileRecord();
                Record.bWidth  = bPtr[Offset + 0];
                Record.bHeight = Record.bWidth;
                short wBitCount = BitConverter.ToInt16(bPtr, Offset + 6);
                Record.bColorCount = (byte)Math.Pow(2, wBitCount);
                Record.bReserved   = 0;
                Record.nID         = BitConverter.ToUInt16(bPtr, Offset + 12);

                TempRecordList.Add(Record);

                if (Record.bWidth == PreferredSize)
                {
                    IsGoodSizedImageAdded = true;
                    recordList.Add(Record);
                }
            }

            if (!IsGoodSizedImageAdded)
            {
                recordList.AddRange(TempRecordList);
            }

            return(true);
        }