loading a Cursor from a cursor (.cur) file

I want to change the cursor in my app for one I have designed but I cannot seem to get the LoadCursorFromFile API call working,

Could somebody please post an example of how to do this. Also my copy of the delphi image editor will not let me set the cursor hot spot - is this a bug?

I have delphi 2.01
essbbAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ronit051397Commented:
1. By the Image Editor which comes with Delphi, create a new resource file on the same directory of the project. Name it as test.res.
2. Draw a cursor and name it as CURSOR_1.
3. Open a new Project.
 In the project file write:

program Project1;

uses
Forms,
Unit1 in 'Unit1.pas' {Form1};

{$R *.RES}
{$test.res}

begin
  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  Application.Run;
end.

5.Place a button on the form.
6. Write the following code:
unit Unit1;
interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
begin
  screen.cursors[1]:=LoadCursor(hInstance, pChar('CURSOR_1'));
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  DestroyCursor(Screen.Cursors[1]);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  Form1.Cursor:=1;
end;

end.


0
essbbAuthor Commented:
Thanks For the answer

Is there any way of loading an existing cursor file (i.e a .cur) into the resource file?

I am not using image editor to create my cursors because it will not let me set the hot spot!
0
mirek071497Commented:
Bad !
When You load *.cur into the Image Editor then in Menu Cursor select Set Hot Spot.

When You lad *.res and Open Cursor then you have the same menu.
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

ronit051397Commented:
Correction:
you should write:
{$R *.RES}
{$R test.res}
and as mirek said you do have a hot spot setting in the image editor.
0
essbbAuthor Commented:
I know about the option on the cursor menu!
The problem is that it does not rememeber the values that I put in. If I change the settings for a new cursor from 0,0 to say 10,10 then when I select test cursor the hot spot is still at 0,0!

Also I would  like to use colour in the cursor and image editor does not support this. B&W cursors only.

0
ronit051397Commented:
1. The HotSpost in the ImageEditor works, I checked.
2. Yes, The ImageEditor supports only B&W cursors.
3. On a buttonclick event write:
screen.cursors[1]:=LoadCursorFromFile('c:\something.cur');
form1.cursor:=1;
4. In the first method you don't need the res file for the installation becuase it is included in the exe file you create.
In the second method you need the cur file to be installed as well as the exe file.

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
essbbAuthor Commented:
Yep that did the trick!

I have tested image editor again and It still will not let me set the hot spot!!

Any Idea what may be causing this? If it works fine on yours then it cannot be a bug with image editor. Do you have delphi 2.01?
0
ronit051397Commented:
No, Version 2.0
0
ronit051397Commented:
The Delphi ImageEditor has some other bugs.
Try to use ImageEditor of the VisualC++ package. But I think it creates only B&W cursors.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.