public static Cursor CreateCursor(Bitmap bmp, int xHotSpot, int yHotSpot)
 {
     IconInfo tmp = new IconInfo();
     GetIconInfo(bmp.GetHicon(), ref tmp);
     tmp.xHotspot = xHotSpot;
     tmp.yHotspot = yHotSpot;
     tmp.fIcon = false;
     return new Cursor(CreateIconIndirect(ref tmp));
 }
Exemple #2
0
 private static System.Windows.Forms.Cursor CreateCursor(Bitmap bmp, int xHotSpot, int yHotSpot)
 {
     IconInfo tmp = new IconInfo();
     GetIconInfo(bmp.GetHicon(), ref tmp);
     tmp.xHotspot = xHotSpot;
     tmp.yHotspot = yHotSpot;
     tmp.fIcon = false;
     return new System.Windows.Forms.Cursor(CreateIconIndirect(ref tmp));
 }
Exemple #3
0
 public static Cursor CreateCursor(Bitmap bmp, int xHotSpot, int yHotSpot)
 {
     IntPtr ptr = bmp.GetHicon();
     IconInfo tmp = new IconInfo();
     GetIconInfo(ptr, ref tmp);
     tmp.xHotspot = xHotSpot;
     tmp.yHotspot = yHotSpot;
     tmp.fIcon = false;
     ptr = CreateIconIndirect(ref tmp);
     return new Cursor(ptr);
 }
 /// <summary>
 /// Loads our Cursor from an Image
 /// </summary>
 /// <param name="path">Path of Image</param>
 /// <param name="xHotSpot">X HotSpot Location</param>
 /// <param name="yHotSpot">Y HotSpot Location</param>
 /// <returns></returns>
 internal static IntPtr LoadCursor(string path, int xHotSpot, int yHotSpot)
 {
     var image = CreateNonIndexedImage(path);
     var bitmapsIntPtr = new Bitmap(image).GetHicon(); //Get Bitmaps handle
     var tmp = new IconInfo();
     GetIconInfo(bitmapsIntPtr, ref tmp); //Get Icon info and pass it back
     tmp.XHotspot = xHotSpot; //Create HotSpots for our Icon
     tmp.YHotspot = yHotSpot;
     tmp.FIcon = false;
     return CreateIconIndirect(ref tmp); //Return the handle for our Icon
 }
Exemple #5
0
 public static Cursor Convert(Bitmap b, int centerX, int centerY)
 {
     IntPtr ptr = b.GetHicon();
     IconInfo tmp = new IconInfo();
     GetIconInfo(ptr, ref tmp);
     tmp.xHotspot = centerX;
     tmp.yHotspot = centerY;
     tmp.fIcon = false;
     ptr = CreateIconIndirect(ref tmp);
     return new Cursor(ptr);
 }
Exemple #6
0
        /// <summary>
        /// Converts an image into a cursor.
        /// </summary>
        /// <param name="source">The Image to be converted.</param>
        /// <returns>The source image as a Cursor.</returns>
        public static Cursor CreateCursor(Image source)
        {
            Bitmap bmpSource = source as Bitmap;
            if (bmpSource == null)
                bmpSource = new Bitmap(source);

            IconInfo iInfo = new IconInfo();
            GetIconInfo(bmpSource.GetHicon(), ref iInfo);
            iInfo.xHotspot = 3;
            iInfo.yHotspot = 3;
            iInfo.fIcon = false;

            return new Cursor(CreateIconIndirect(ref iInfo));
        }
        public static Bitmap GetBitmapForIcon(Icon icon)
        {
            using (IconInfo iconInfo = new IconInfo(icon))
            {
                if (!iconInfo.Info.fIcon)
                    return null; // this is a cursor!

                if (iconInfo.BitmapStruct.bmBitsPixel!=32)
                    return Bitmap.FromHicon(icon.Handle);  // no alpha blending, so use regular .Net

                Bitmap iconBitmap = Bitmap.FromHbitmap(iconInfo.Info.hbmColor);

                // get broken bitmap (broken - pixelformat doesn't specify alpha channel, even though the alpha data is there),
                // copy to a new bitmap with a healthy (includes the alpha channel) pixelformat
                Bitmap transparentBitmap;
                using (LockedBitMap lockedBitmap = new LockedBitMap(iconBitmap))
                {
                    transparentBitmap = new Bitmap(lockedBitmap.Data.Width, lockedBitmap.Data.Height, lockedBitmap.Data.Stride, PixelFormat.Format32bppArgb, lockedBitmap.Data.Scan0);
                }
                return transparentBitmap;
            }
        }
Exemple #8
0
 private static extern IntPtr CreateIconIndirect(ref IconInfo icon);
Exemple #9
0
 private static extern bool GetIconInfo(IntPtr hIcon, ref IconInfo pIconInfo);
Exemple #10
0
        /// <summary>
        ///   Create a cursor from the given Resource Name
        /// </summary>
        /// <param name = "resourceName"></param>
        /// <param name = "xHotSpot"></param>
        /// <param name = "yHotSpot"></param>
        /// <returns></returns>
        public static Cursor CreateCursorFromResource(string resourceName, int xHotSpot, int yHotSpot)
        {
            ResourceManager resourceManager = new ResourceManager("MPTagThat.Properties.Resources",
                                                            Assembly.GetCallingAssembly());
              Bitmap bmp = (Bitmap)resourceManager.GetObject(resourceName);

              if (bmp != null)
              {
            IntPtr ptr = bmp.GetHicon();
            IconInfo tmp = new IconInfo();
            GetIconInfo(ptr, ref tmp);
            tmp.xHotspot = xHotSpot;
            tmp.yHotspot = yHotSpot;
            tmp.fIcon = false;
            ptr = CreateIconIndirect(ref tmp);
            return new Cursor(ptr);
              }
              return Cursors.Default;
        }
 public static extern bool GetIconInfo(IntPtr hIcon, out IconInfo piconinfo);
Exemple #12
0
 internal static extern IntPtr CreateIconIndirect([In] ref IconInfo piconinfo);
Exemple #13
0
		internal static extern bool GetIconInfo (IntPtr hIcon, out IconInfo iconinfo);
        private Cursor GenerateCursor(string text)
        {
            Bitmap imgColor = new Bitmap(32, 32, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
            Color color = Color.MidnightBlue;
            SolidBrush brush = new SolidBrush(color);
            SolidBrush brushMask = new SolidBrush(Color.White);
            string s = text;
            System.Drawing.Font fnt = new Font(FontFamily.GenericSerif, 10, FontStyle.Bold);
            using (Graphics g = Graphics.FromImage(imgColor))
            {
                SizeF size = g.MeasureString(s, fnt);
                if (size.Width > 32) size.Width = 32;
                if (size.Height > 32) size.Height = 32;
                g.FillRectangle(brushMask, 0, 0, 32, 32);
                g.DrawString(s, fnt, brush, (32 - size.Width) / 2, (32 - size.Height) / 2);
                g.Flush();
                //g.DrawRectangle(Pens.OrangeRed, new Rectangle(1, 1, 30, 30));
            }
            imgColor.MakeTransparent(Color.White);
            IconInfo ii = new IconInfo();
            ii.fIcon = false;
            ii.xHotspot = 16;
            ii.yHotspot = 16;
            ii.hbmMask = imgColor.GetHbitmap();
            ii.hbmColor = imgColor.GetHbitmap();
            unsafe
            {

                IntPtr iiPtr = new IntPtr(&ii);
                IntPtr curPtr = CreateIconIndirect(iiPtr);
                return new Cursor(curPtr);
            }
        }
Exemple #15
0
 public static extern IntPtr CreateIconIndirect(ref IconInfo icon);
Exemple #16
0
 public static extern bool GetIconInfo(IntPtr hIcon, ref IconInfo pIconInfo);
Exemple #17
0
 internal static extern bool GetIconInfo(IntPtr hIcon, out IconInfo iconinfo);