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 find something on this in the newsgroups but came up with
nada:
I'm trying to create a custom cursor in VS2005. I have a .cur file
that I have put in my "Resources" folder. The resource manager does
not recognize the .cur extension and puts it under the generic "Files"
category (vs. "Images", "Icons", "Strings", etc.)
When I try to refer to the cursor, like:
Properties.Resources.arrowTrans, apparently it comes out to a byte[].
How can I convert this into a Cursor object?
I used to have code in 2003 that used the GetManifestResourceStream
method, but that doesn't work. And how does the
"BaseApplicationManifest" option work in the "Build Action" item (vs.
"None", "Embedded Resource", "Compile", and "Content") in the file
Properties window?
Thanks,
Jon"
And nobody has responded to him for the last MONTH. I just recently posted
almost the exact same question today, so I guess I'm out of luck until at
least next year to find out how to do this...lol
So I guess nobody knows how to use.CUR files or make a custom cursor form a
bitmap. Don't feel too bad. Neither does MSDN2, as their example doesn't
work...
http://msdn2.microsoft.com/en-us/library/system.windows.forms.cursor.aspx
So I guess MS itself is keeping this a secret. Oh goody! : )
[==P==]
Willy Denoyette [MVP] - 16 Dec 2005 22:31 GMT
W
> 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
[quoted text clipped - 36 lines]
>
> [==P==]
Supposed your cursor file is named MyCursor.cur, you'll have to build the
sample
cl /clr msdn2sample.cpp /link
/assemblyresource:MyCursor.Cur,CustomCursor.MyCursor.Cur
Willy.
Willy Denoyette [MVP] - 16 Dec 2005 22:34 GMT
> http://msdn2.microsoft.com/en-us/library/system.windows.forms.cursor.aspx
>
> So I guess MS itself is keeping this a secret. Oh goody! : )
>
> [==P==]
Just realized I could better post the complete sample.
// command line build:
// cl /clr ccursor.cpp /link
/assemblyresource:Cursor1.Cur,CustomCursor.Cursor1.Cur
#using "System.dll"
#using "System.drawing.dll"
#using "System.Windows.Forms.dll"
using namespace System;
using namespace System::Drawing;
using namespace System::Windows::Forms;
namespace CustomCursor
{
public ref class Form1: public System::Windows::Forms::Form
{
public:
Form1()
{
this->ClientSize = System::Drawing::Size( 292, 266 );
this->Text = "Cursor Example";
this->Cursor = gcnew System::Windows::Forms::Cursor(
GetType(),"Cursor1.Cur" );
}
};
}
[STAThread]
int main()
{
Application::Run( gcnew CustomCursor::Form1 );
}
Willy.
Peter Oliphant - 16 Dec 2005 22:53 GMT
The code you listed is verbatim the code sample provided by MS on their
webpage I gave a link to that I've tested and doesn't work (at least for me
it doesn't):
http://msdn2.microsoft.com/en-us/library/system.windows.forms.cursor.aspx
Have you tried the code? Does it work for you (note: it compiles just fine,
but it doesn't run just fine (null exception error)...
[==P==]
>> http://msdn2.microsoft.com/en-us/library/system.windows.forms.cursor.aspx
>>
[quoted text clipped - 38 lines]
>
> Willy.
James Park - 16 Dec 2005 23:41 GMT
I know of two ways to get the thing working:
1. Have an icon named Cursor1.Cur
2. Use linker option /ASSEMBLYRESOURCE:"Cursor1.Cur"
3. Use the following line to get at the cursor:
gcnew
System::Windows::Forms::Cursor(System::Reflection::Assembly::GetExecutingAssembly()->GetManifestResourceStream("Cursor1.Cur"));
The other way:
1. Have an icon named CustomCursor.Cursor1.Cur
2. Use linker option /ASSEMBLYRESOURCE:"CustomCursor.Cursor1.Cur"
3. Use the following line to get at the cursor (assuming AnyClass is in the
namespace CustomCursor):
gcnew System::Windows::Forms::Cursor(AnyClass::typeid, "Cursor1.Cur");
Hope this helps.
> The code you listed is verbatim the code sample provided by MS on their
> webpage I gave a link to that I've tested and doesn't work (at least for
[quoted text clipped - 49 lines]
>>
>> Willy.
Willy Denoyette [MVP] - 17 Dec 2005 09:43 GMT
Sure I did, question is, did you run the command line compile command as
included in the snip?
cl /clr ccursor.cpp /link
/assemblyresource:Cursor1.Cur,CustomCursor.Cursor1.Cur
Note the /assemblyresource linker option, you need to substitute your cursor
file name with the Cursor1.cur name in the above command.
The sole problem with the msdn2 samples is that the description of the
resource embedding is only valid for C#, not for the other language samples.
Willy.
Willy.
> The code you listed is verbatim the code sample provided by MS on their
> webpage I gave a link to that I've tested and doesn't work (at least for
[quoted text clipped - 49 lines]
>>
>> Willy.
Wendelldh - 04 Jun 2006 20:57 GMT
Hi, I am not sure if you ever got an appropriate response to your
question, so I will tell you what I did.
I could not get this working by adding the cursor to the Resources in
VS 2005.
What I did was I added and 'Images' folder to the project.
I then put m cursors in this folder.
Then I set the Build Action property of each cursor to embeded
resource.
The if you look at the properties for the project, under 'Application'
you will see what the 'Default namespace:' is.
Now to load the embeded resource cursor, you would do this...
Cursor m_BurnCursor = new
Cursor(Assembly.GetExecutingAssembly().GetManifestResourceStream("MyProjectNamespace.Images.MyCursor.cur"));
Where MyProjectNamespace is replaced by the default namespace found
above for the project and MyCursor.cur is replaced by the name of your
curesor.
I noticed in the MSDN2 page the was mentioned in the responses to your
question it says that the Cursor class does not support Animated and
any cursor that is not black and white. I have never tried animated,
but color did work for me.
I hope this helps.
I hope this helps in some way.