views:

424

answers:

1

Hey, I've been trying to write code that loads a .png file, attaches hotspot information, and saves it to a .cur file.

So far I have code to create a System.Windows.Forms.Cursor object, which I'll post below:

        Bitmap bmp = new Bitmap(source_image);
        IconInfo inf = new IconInfo();
        GetIconInfo(bmp.GetHicon(), ref inf);
        inf.xHotspot = /* code to get x hotspot */;
        inf.yHotspot = /* code to get y hotspot */;
        inf.fIcon = false;
        IntPtr iconPtr = CreateIconIndirect(ref inf);
        return new Cursor(iconPtr);

I took it directly from this tutorial.

I've gotten the cursor to work properly within my application, there just seems to be no way to save it to a file. Any help guys?

+1  A: 

I don't think there is a function to save to a file, you probably have to write out the file with correct headers on your own, see Icons in Win32 for format details (x and y in planes and bpp fields IIRC)

Anders
That's what I ended up having to do to make custom cursors, save to an ico and change the necessary bits in a hex editor. I might end up actually doing that programmatically though.
MiffTheFox
And yes, I used Icon.Save to save it to a MemoryStream, then just set the required bytes by hand.
MiffTheFox