|
Hi, the Cursors.Hand mouse cursor icon (the one used for hyperlinks etc.) shows some .NET default icon, along with several more that aren't generally available in Windows. But this one is not the cursor that's configured for that purpose in the Windows settings (Control panel -> Mouse -> Pointers...). When I try to load the real cursor from the file (the location can be read from the registry), the Cursor class only tells me this format is not supported. Well, it's a cursor file (.cur) that runs fine with Windows, why can't the Cursor class handle it? It seems there's no way around the Cursor class. For example, even the hand cursor from Windows Vista doesn't work with .NET. Is there a solution or will I have to live with the .NET default hand cursor?
|
| LonelyPixel Thursday, April 26, 2007 10:19 AM |
The framework uses the old-fashioned IPicture COM interface to load the cursor. It probably doesn't support animated and colored cursors. This workaround worked for me:
using System; using System.Windows.Forms; using System.Runtime.InteropServices;
namespace WindowsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)] private static extern IntPtr LoadCursorFromFile(string path);
private void Form1_Load(object sender, EventArgs e) { this.Cursor = new Cursor(LoadCursorFromFile(@"c:\windows\cursors\3dgarro.cur")); } } }
|
| nobugz Thursday, April 26, 2007 1:13 PM |
Here is my code that creates cursor from cur embeded resource file:
Cursor = new Cursor(GetType().Assembly.GetManifestResourceStream(GetType(), "Cursors.ZoomIn.cur")); myControl.Cursor = Cursor;Where Cursors is the Folder that contains my cursors and ZoomIn.cur is the cursor, created with VS designer. |
| boban.s Thursday, April 26, 2007 10:39 AM |
I know how to read cursors from files, there's a constructor Cursor(string fileName) that loads the cursor into the object. But this constructor throws an exception when you try that with certain .cur files. I have tested several files, most from Windows XP itself. Some are only loaded in wrong colours (I think it was the coloured ones), some few were loaded correctly, and the said hand cursor (one from Mac OS X and one from Windows Vista) could not be loaded. Why?
|
| LonelyPixel Thursday, April 26, 2007 11:03 AM |
Can you give us an example of a Windows XP cursor that doesn't load correctly?
|
| nobugz Thursday, April 26, 2007 11:19 AM |
When i was doing the same, i was unable to load created cursor with some other program for icons, and to load from file. I was forced to this way of loading and create them with VS designer. I believe the problem is cursor size and color palete. |
| boban.s Thursday, April 26, 2007 11:25 AM |
For example, C:\Windows\Cursors\3dgarro.cur doesn't load correctly. From Windows Vista, it's the file aero_link.cur, no idea in what directory it was originally (I copied it into the XP system and use it there for links, and browsers also use that cursor).
|
| LonelyPixel Thursday, April 26, 2007 11:49 AM |
The framework uses the old-fashioned IPicture COM interface to load the cursor. It probably doesn't support animated and colored cursors. This workaround worked for me:
using System; using System.Windows.Forms; using System.Runtime.InteropServices;
namespace WindowsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)] private static extern IntPtr LoadCursorFromFile(string path);
private void Form1_Load(object sender, EventArgs e) { this.Cursor = new Cursor(LoadCursorFromFile(@"c:\windows\cursors\3dgarro.cur")); } } }
|
| nobugz Thursday, April 26, 2007 1:13 PM |
Thank you very much, LoadCursorFromFile does exactly what I want. Supports standard coloured cursors (XP) and those with partial transparency like Mac's and Vista's.
Before, I had also tried something else with LoadImage(NULL, OCR_HAND, IMAGE_CURSOR, 0, 0, LR_DEFAULTSIZE) but it didn't work. GetLastError() would always return 1813 (Resource not found). But this is very nice, I can now build my abstraction code around it as I originally had planned.
|
| LonelyPixel Thursday, April 26, 2007 7:51 PM |
How would it be done in VC++ .net 2003...???
Upload a self made cursor in ma program... |
| FZ18 Tuesday, September 22, 2009 11:23 PM |