By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,230 Members | 2,427 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,230 IT Pros & Developers. It's quick & easy.

Color Cursor from Embedded Resource

P: n/a
If anyone has any ideas, or a better forum to post in, please let me know.

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 you 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;
}
Nov 16 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.