Tmuna

Tmuna

  • NA
  • 7
  • 0

Colorful Cursor

Jan 23 2010 4:10 PM

I'm trying to make the mouse cursor change into a colorful one, but the cursor class doesn't support animated cursors.
I found a "step by step" guide for that, but it seems to be (by the replies of the article), that I'm the only one that didn't succeed. The link is: http://leifw.wickland.net/2006/08/loading-color-cursor-in-net-20.html
What I did is added a .cur file to resources, and patsed the grey lines (from the link above) in my class.
The following code didn't get compiled and the error was that the "WriteAllBytes" function should get a byte[] variable and not a bitmap... therefore I've added code lines that convert a bitmap to a bytes array.
But it still didn't help, and after running the code I get the folowing error: "Win32 handle passed to Cursor is not valid or is the wrong type."
This is what I'm trying to run:
----------------------------------------------
//This line was added in the using section -> using System.Runtime.InteropServices;
[DllImport("user32.dll")]
static extern IntPtr LoadCursorFromFile(string lpFileName);
private Cursor LoadColorHandCursor()
{
Image image = Properties.Resources.hand2;
MemoryStream stream = new MemoryStream();
image.Save(stream, System.Drawing.Imaging.ImageFormat.Bmp);
Byte[] bytes = stream.ToArray();
string path = Path.GetTempFileName();
File.WriteAllBytes(path, bytes);
Cursor hand = new Cursor(LoadCursorFromFile(path));
File.Delete(path);
return hand;
}
Cursor
.Current = LoadColorHandCursor();
----------------------------------------------
I have no idea whats wrong, it could be I didn't understand excactly what was explained to do in the link above.
If anyone knows whats wrong with my code, or has any other idea, it will really help me.
p.s: If this code works, it means I could use any image file as the source file, and the code converts it into a colorful cursor (not only .cur files)?
Thanks in advanced,