Solved

loading a Cursor  from a cursor (.cur) file

Posted on 1997-08-06
9
794 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

Author Comment

by:essbb
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
No, Version 2.0
0
 
LVL 5

Expert Comment

by:ronit051397
Comment Utility
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

763 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

13 Experts available now in Live!

Get 1:1 Help Now