Load Color Cursor from Embedded Resource

A

Andrew Roesch

Hello all,

I believe I have a tough one today. I'm trying to load a color cursor from
an embedded resource in C# and am having quite a bit of trouble doing it.
Let me tell what I have found out already.

Firstly, the normal "new Cursor(GetType(), "Cursor.cur")" will not work with
cursors in color.

However I did find an example online that works when given a filename and
I've included the code for anyone who needs it. It uses a dllimport to use a
function called LoadCursorFromFileW. How can I adapt this or use a similar
approach to use a Cursor that is an embedded resource in my C# project.


public class CursorFactory {
[DllImport("user32.dll", EntryPoint = "LoadCursorFromFileW",
CharSet = CharSet.Unicode)]
private static extern IntPtr LoadCursorFromFile(String str);

public static Cursor Create(string filename){
IntPtr hCursor;
Cursor result = null;
try {
hCursor = LoadCursorFromFile(filename);
if (!IntPtr.Zero.Equals(hCursor)) {
result = new Cursor(hCursor);
} else {
throw new
ApplicationException("Could not create cursor from file "
+ filename);
}
} catch(Exception ex) {
//log exception
}

return result;
}
 
A

Andrew Roesch

Sorry to bump, but I did write in on a friday. Does anyone have any ideas?
I've begun to look at the LoadCursor function in user32 but so far I've not
made any progress.

Andrew
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top