Solved

loading a Cursor  from a cursor (.cur) file

Posted on 1997-08-06
9
831 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

691 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