Solved

loading a Cursor  from a cursor (.cur) file

Posted on 1997-08-06
9
816 Views
Last Modified: 2010-04-04
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
0
Comment
Question by:essbb
  • 5
  • 3
9 Comments
 
LVL 5

Expert Comment

by:ronit051397
ID: 1340716
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
 

Author Comment

by:essbb
ID: 1340717
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
 
LVL 3

Expert Comment

by:mirek071497
ID: 1340718
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
 
LVL 5

Expert Comment

by:ronit051397
ID: 1340719
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:essbb
ID: 1340720
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
 
LVL 5

Accepted Solution

by:
ronit051397 earned 50 total points
ID: 1340721
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
 

Author Comment

by:essbb
ID: 1340722
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
 
LVL 5

Expert Comment

by:ronit051397
ID: 1340723
No, Version 2.0
0
 
LVL 5

Expert Comment

by:ronit051397
ID: 1340724
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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now