473,403 Members | 2,284 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

Load Color Cursor from Embedded Resource

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;
}

Nov 16 '05 #1
1 7236
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

"Andrew Roesch" <no****@nospam.com> wrote in message
news:OX****************@TK2MSFTNGP11.phx.gbl...
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;
}

Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Ed Sutton | last post by:
I have been searching for how to get an icon resource and load it into an ImageList. I added an *.ico file to my project and set the files "Build Action" to "Embedded Resource". Is there any easy...
2
by: Ed Sutton | last post by:
What's the trick to loading an icon from the embedded resources? Here are the steps I have taken: ------------------------- 1 - I added a file named "FOLDER01.ICO" to my solution project 2 - I...
2
by: Paul Cheetham | last post by:
Hi, I am trying to load a custom cursor from my programs resources. I have successfully included the cursor resource, and I have confirmed that the name I am using is correct. Below is the...
4
by: Schorschi | last post by:
I am trying to mimic the following (which works) but Use the stock GetManifestResourceStream route. For example Public Declare Unicode Function LoadCursorFromFile Lib "USER32.DLL" Alias...
6
by: Peter Oliphant | last post by:
I've now asked how three times in this forum with no answers. So I went to the 'windowsforms' newsgroup, and found this post, also unanswered, with the same problem: "Hello, I've tried to...
7
by: H. Williams | last post by:
I know the .Net Cursor class doesn't work with color cursors. So I'm currently using the LoadCursorFromFile API with reflection to set color cursors: here is my code: public static extern...
5
by: Paul Cheetham | last post by:
Hi, I have some custom colour cursors which I have added to my c# project, and set them to be compiled as "Embedded Resource" It seems impossible to load a colour cursor using the standard...
8
by: John Dunn | last post by:
Since currently we aren't allowed to have compiled XAML files embedded in C++ apps I'm using Markup::XamlReader::Load to dynamically load XAML files. This works perfectly fine with external files...
4
by: bern11 | last post by:
How do you embed a custom cursor? The help says: // On the command line: // Add the following flag: // /res:CursorFileName.Cur,Namespace.CursorFileName.Cur What if you are...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.