Results 1 to 3 of 3

Thread: [2.0] Using Color cursors from resources.

  1. #1

    Thread Starter
    Frenzied Member conipto's Avatar
    Join Date
    Jun 2005
    Location
    Chicago
    Posts
    1,175

    [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
    Hate Adobe Acrobat? My Codebank Sumbissions - Easy CodeDom Expression evaluator: (VB / C# ) -- C# Scrolling Text Display

    I Like to code when drunk. Don't say you weren't warned.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Frenzied Member conipto's Avatar
    Join Date
    Jun 2005
    Location
    Chicago
    Posts
    1,175

    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
    Hate Adobe Acrobat? My Codebank Sumbissions - Easy CodeDom Expression evaluator: (VB / C# ) -- C# Scrolling Text Display

    I Like to code when drunk. Don't say you weren't warned.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width