|
-
Apr 2nd, 2006, 02:01 AM
#1
Thread Starter
Frenzied Member
[2.0] Using Color cursors from resources.
Ok, so much to my dismay, it appears the .NET framework doesn't support color Mouse Cursors. That's fine, since searching around, I found a suitable API method that seems to work.
Code:
#region API Calls for Color Cursor use..
[DllImport("user32.dll")]
public static extern IntPtr LoadCursorFromFile(string fileName);
[DllImport("user32.dll")]
public static extern IntPtr SetCursor(IntPtr cursorHandle);
[DllImport("user32.dll")]
public static extern uint DestroyCursor(IntPtr cursorHandle);
#endregion
/// <summary>
/// It's insane how much code it takes to load a color cursor. geez.
/// </summary>
private void Surface_MouseEnter(object sender, EventArgs e)
{
Cursor myCursor = new Cursor(GetType(), "PencilCursor.cur");
IntPtr colorCursorHandle = LoadCursorFromFile("PencilCursor.cur" );
myCursor.GetType().InvokeMember("handle",BindingFlags.Public | BindingFlags.NonPublic |BindingFlags.Instance | System.Reflection.BindingFlags.SetField,null,myCursor,new object [] { colorCursorHandle } );
this.Cursor = myCursor;
}
However, This only works if the cursor file is in the apps executable directory. Originally, I had just added the cursor to the project, and changed it's built action to Embed Resource. This allowed the first call in the funciton to load it from the resource manifest, which was great, but it was solid black. Is there a way to use the API method which loads a color cursor, but with my embedded resource?
Bill
-
Apr 2nd, 2006, 02:35 AM
#2
Re: [2.0] Using Color cursors from resources.
There's a LoadCursor API as well that specifically loads a cursor from a resource. Don't have a usage example though.
-
Apr 2nd, 2006, 03:21 AM
#3
Thread Starter
Frenzied Member
Re: [2.0] Using Color cursors from resources.
After trying to get the LoadCursor API function to work for a while, I started to look around for examples.. and found this page:
http://www.pinvoke.net/default.aspx/...oadCursor.html
With the author saying it doesn't seem to work right for embedded resources 
Pretty much no matter what I do, it just loads a nothing cursor... Has anyone ever used this method with a color cursor?
Bill
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|