using System; using System.Collections.Generic; using System.Text; using System.IO; using System.ComponentModel; using System.Runtime.InteropServices; namespace Vestris.ResourceLib { /// /// This structure depicts the organization of data in a cursor resource. /// public class CursorResource : IconImageResource { private UInt16 _hotspotx = 0; private UInt16 _hotspoty = 0; /// /// An existing cursor resource. /// /// Module handle. /// Resource ID. /// Resource type. /// Resource name. /// Language ID. /// Resource size. internal CursorResource(IntPtr hModule, IntPtr hResource, ResourceId type, ResourceId name, UInt16 language, int size) : base(hModule, hResource, type, name, language, size) { } /// /// A new cursor resource. /// public CursorResource() : base(new ResourceId(Kernel32.ResourceTypes.RT_CURSOR)) { } /// /// Convert into an icon resource that can be written into an executable. /// /// Icon image. /// Icon Id. /// Language. /// An icon resource. public CursorResource(IconFileIcon icon, ResourceId id, UInt16 language) : base(icon, new ResourceId(Kernel32.ResourceTypes.RT_CURSOR), id, language) { } /// /// Horizontal hotspot coordinate. /// The hot spot of a cursor is the point to which Windows refers in tracking the cursor's position. /// public UInt16 HotspotX { get { return _hotspotx; } set { _hotspotx = value; } } /// /// Vertical hot spot coordinate. /// The hot spot of a cursor is the point to which Windows refers in tracking the cursor's position. /// public UInt16 HotspotY { get { return _hotspoty; } set { _hotspoty = value; } } /// /// Write the cursor data to a file. /// /// Target executable file. public override void SaveIconTo(string filename) { byte[] dataWithHotspot = new byte[Image.Data.Length + 4]; Buffer.BlockCopy(Image.Data, 0, dataWithHotspot, 4, Image.Data.Length); dataWithHotspot[0] = (byte)(HotspotX & 0xFF); dataWithHotspot[1] = (byte)(HotspotX >> 8); dataWithHotspot[2] = (byte)(HotspotY & 0xFF); dataWithHotspot[3] = (byte)(HotspotY >> 8); SaveTo(filename, _type, new ResourceId(_header.nID), _language, dataWithHotspot); } /// /// Read DIB image. /// /// DIB bits. /// DIB size. internal override void ReadImage(IntPtr dibBits, UInt32 size) { _hotspotx = (UInt16) Marshal.ReadInt16(dibBits); dibBits = new IntPtr(dibBits.ToInt32() + sizeof(UInt16)); _hotspoty = (UInt16) Marshal.ReadInt16(dibBits); dibBits = new IntPtr(dibBits.ToInt32() + sizeof(UInt16)); base.ReadImage(dibBits, size - 2 * sizeof(UInt16)); } } }