Angel_Hernandez

How do make a custom cursor on VC++ Express.... This is what i have to make it with... But i get an error... Please help

In Visual Studio C++ 2003 no error occur with this code.... It runs fine!!!

//statement

HCURSOR Custom_Cur=LoadCursorFromFile("Target.cur");

//error

Error 1 error C2664: 'LoadCursorFromFileW' : cannot convert parameter 1 from 'const char [11]' to 'LPCWST'




Re: Visual C++ Express Edition Custom Cursors

crescens2k

This is because the project is set to Unicode. Either use the TEXT macro or set the project to multi byte.

HCURSOR Custom_Cur=LoadCursorFromFile(TEXT("Target.cur"));

If you do this then you will have to include the tchar.h header file.





Re: Visual C++ Express Edition Custom Cursors

Angel_Hernandez

I did this and it gave me and error

//header file

#include <tchar.h>

//code

HCURSOR Custom_Cur=LoadCursorFromFile(TEXT("Target.cur"));

System::Windows::Forms::Cursor^ Target= gcnew System::Windows::Forms::Cursor(Custom_Cur);

this->Cursor=Target;

//error

Error 1 error C2664: 'System::Windows::Forms::Cursor::Cursor(System::IntPtr)' : cannot convert parameter 1 from 'HCURSOR' to 'System::IntPtr'






Re: Visual C++ Express Edition Custom Cursors

crescens2k

Well yes, of course it would since you are not putting the handle into the correct format. Handles are void* so it is seen as a different type. You would need to cast it to an integral type.
But out of idle curiosity, why are you going through that method of loading a cursor. Why not just use:
System::Windows::Forms::Cursor^ Target = gcnew System::Windows::Forms::Cursor("Target.cur");

One of the overloads of the Cursor constructor is a string which contains the file name of the cursor you wish to load.





Re: Visual C++ Express Edition Custom Cursors

Angel_Hernandez

When i set it up this way the cursor does load but it doesn't show up in color only in black.... I have also tryed this in VC++ 2003 and the same result... Also it crashes when you use an animated cursor.. Do you have any suggestion in which to set up a regular (.cur) and (.ani) custom cursor. Thank You!!!!

//does work but doesn't come in color only black

System::Windows::Forms::Cursor^ Target= gcnew System::Windows::Forms::Cursor("Target.cur");

this->Cursor=Target;






Re: Visual C++ Express Edition Custom Cursors

nobugz

You are correct, the framework cannot handle colored and animated cursors. All you need is a cast:

Code Snippet
HCURSOR Custom_Cur=LoadCursorFromFile(TEXT("c:\\windows\\cursors\\appstart.ani"));
System::Windows::Forms::Cursor^ Target= gcnew System::Windows::Forms::Cursor((IntPtr)Custom_Cur);
this->Cursor=Target;

Note that you'll have to change the Linker + Input + Dependencies project setting to get the program to link. Delete $(NOINHERIT).






Re: Visual C++ Express Edition Custom Cursors

Angel_Hernandez

I go to my Project setting and go under Project dependencies and there nothing under depends on... I don't know were the linker+ Input are...

I tryed the code you put up and it gave me errors... I tryed different way similar to this and gave the exact errors.... Can you please tell me why this happen... and is there a solution... Thank You...

//code

HCURSOR Custom_Cur=LoadCursorFromFile(TEXT("c:\\windows\\cursors\\appstart.ani"));
System::Windows::Forms::Cursor^ Target= gcnew System::Windows::Forms::Cursor((IntPtr)Custom_Cur);

this->Cursor=Target;

//errors

Error 43 error LNK2019: unresolved external symbol "extern "C" struct HICON__ * __stdcall LoadCursorFromFileW(wchar_t const *)" ( LoadCursorFromFileW@@$$J14YGPAUHICON__@@PB_W@Z) referenced in function "private: void __clrcall SouthParkShooters::Form1::Form1_Load(class System:Surprisebject ^,class System::EventArgs ^)" ( Form1_Load@Form1@SouthParkShooters@@$$FA$AAMXP$AAVObject@System@@P$AAVEventArgs@4@@Z) South Park Shooters.obj

Error 42 error LNK2028: unresolved token (0A00001B) "extern "C" struct HICON__ * __stdcall LoadCursorFromFileW(wchar_t const *)" ( LoadCursorFromFileW@@$$J14YGPAUHICON__@@PB_W@Z) referenced in function "private: void __clrcall SouthParkShooters::Form1::Form1_Load(class System:Surprisebject ^,class System::EventArgs ^)" ( Form1_Load@Form1@SouthParkShooters@@$$FA$AAMXP$AAVObject@System@@P$AAVEventArgs@4@@Z) South Park Shooters.obj

Error 44 fatal error LNK1120: 2 unresolved externals C:\Users\Angel Hernandez\Documents\Visual Studio 2005\Visual C++ Projects\South Park Shooters\Debug\South Park Shooters.exe






Re: Visual C++ Express Edition Custom Cursors

nobugz

Yes, those are the linker errors I warned about. You are looking at the wrong "dependencies". Project + properties, Configuration properties, Linker, Input, "Additional Dependencies". Click on the dots and turn on the checkbox.





Re: Visual C++ Express Edition Custom Cursors

Angel_Hernandez

Thanks it works.....

//code

HCURSOR Custom_Cur=LoadCursorFromFileA("Target.cur");

System::Windows::Forms::Cursor^ Target= gcnew System::Windows::Forms::Cursor((IntPtr)Custom_Cur);

this->Cursor=Target;