Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Delphi : Using custom cursors

828 views
Skip to first unread message

Andrew Crouch

unread,
Jun 13, 1995, 3:00:00 AM6/13/95
to
I am trying to add a custom cursor to a Delphi application. I've done
everything it says in the help file but I can't get it to work.

I've defind my cursor with the Image Editor, used the resource compiler
(BRCC.EXE in the \delphi\bin directory) to turn my .rc file into a .res
file. In the code I've used the $R compiler directive to include the
resource file and used LoadCursor to add the custom cursor to the Cursors
array. Everything compiles okay but when I run the program the cursor
doesn't change.

Anyone know what I'm doing wrong ?

Thanks in advance

Andy Crouch
Senior Systems Engineer
De Montfort University, Milton Keynes, UK
e-mail acr...@dmu.ac.uk

James N. Potts

unread,
Jun 13, 1995, 3:00:00 AM6/13/95
to
Andrew Crouch <acr...@dmu.ac.uk> writes:

>I am trying to add a custom cursor to a Delphi application. I've done
>everything it says in the help file but I can't get it to work.

The help file doesn't do a good job with this.

1. Make sure you use all caps when calling loadcursor, ie
Cursors[MyCustomCursorConstant]:= loadcursor(hinstance,'MYCURSOR');

2. Make sure you pass the proper instance to loadcursor (see above example).

3. Do not put your cursors in a resource file with the same name as your
project.

4. See if loadcursor is finding the cursor or not. Check to see if it
returns 0 or not. If it returns 0, your problem is probably one of the
three above.

5. When you change the change the cursor, use the screen cursor, ie
Screen.Cursor:= MyCustomCursorConstant;

6. When you switch to a custom cursor, throw in a ProcessMessages call right
after it. This ensures that the cursor will be changed before any
selfish code gets run.

Following these rules, I finally got my custom cursors working.

-Jim

_____________________________________________________________________
James N. Potts| "You have to be a real stud hombre cybermuffin
ja...@cs.iastate.edu| to handle Windows."
jnp...@iastate.edu| - Dave Barry

Josha J. Munnik

unread,
Jun 16, 1995, 3:00:00 AM6/16/95
to acr...@dmu.ac.uk
Hi,

>I've defind my cursor with the Image Editor, used the resource compiler
>(BRCC.EXE in the \delphi\bin directory) to turn my .rc file into a .res
>file.

You can also create .RES files directly from within Image Editor.

>In the code I've used the $R compiler directive to include the
>resource file and used LoadCursor to add the custom cursor to the Cursors
>array.

>Everything compiles okay but when I run the program the cursor
>doesn't change.

At which number have you placed it ?

Anyhow I don't know how to make the cursor visible all the time, but you can
set this number in the cursor field of your form and components. Moving into
the form or component will alter the cursor to your loaded cursor.

Hope this helps a little,

Greetings

Josha.
_________________________________________________________________
I-ViSaGE | "The guide says there is an art to
Josha Munnik | flying," said Ford, "or rather a knack.
mun...@cs.utwente.nl | The knack lies in learning how to throw
tel: +31-(0)74.502953 | yourself to the ground and miss."
fax: +31-(0)10.4769477 |
_______________________| (The Hitchhikers guide to the Galaxy)


jjo...@jack.clarku.edu

unread,
Jun 21, 1995, 3:00:00 AM6/21/95
to

I am encountering cursor problems with the dragcursor property;
I cannot reset it, either at run time or design time (actually,
I reset it, but the dragcursor itself does not change). Thinking
it may be a problem of context, I reset the property for both
my listbox (where the dragging is to be done) and the main form,
and this still does not allow the cursor change.

I wish I had a solution rather than a problem to add to this
discussion . . .

Jeff Jones

James N. Potts

unread,
Jun 21, 1995, 3:00:00 AM6/21/95
to
dav...@bruce.cs.monash.edu.au (Andrew Davison) writes:

>I have the same problem (except that I'm using the resourse workshop to
>edit the default .res file...*shrug*)
>
> You should look at the value returned from LoadCursor... I'm getting 0,,
> and don't understand why.

I encountered this problem. The solution: don't touch the default .res file!
Make another .res, and include it in your source. Then everything should
work fine.

John Reid

unread,
Jun 21, 1995, 3:00:00 AM6/21/95
to
In article <3s8m6t$7...@harbinger.cc.monash.edu.au>,
dav...@bruce.cs.monash.edu.au (Andrew Davison) wrote:
> Andrew Crouch (acr...@dmu.ac.uk) wrote:
> : I am trying to add a custom cursor to a Delphi application. I've done

> : everything it says in the help file but I can't get it to work.
>
> : I've defind my cursor with the Image Editor, used the resource compiler

> : (BRCC.EXE in the \delphi\bin directory) to turn my .rc file into a .res
> : file. In the code I've used the $R compiler directive to include the
> : resource file and used LoadCursor to add the custom cursor to the Cursors
> : array. Everything compiles okay but when I run the program the cursor
> : doesn't change.
>
> I have the same problem (except that I'm using the resourse workshop to
> edit the default .res file...*shrug*)
>
> You should look at the value returned from LoadCursor... I'm getting 0,,
> and don't understand why.

The value returned will always be 0, and the example *is* wrong. Check the
Windows API as regards the first parameter to the API call LoadCursor to
see why, then check out the code below:

(See earlier posting on getting the cursor resource into your executable)

const crHandpoint = 20; { or some such number > 16 }

Screen.Cursors[crHandpoint] :=
LoadCursor(GetClassWord(Handle,GCW_HMODULE),'HANDPOINT'));

{ and in the OnActivate handler of the form }

MyForm.Cursor := crHandpoint;

This is, I would imagine, the most elegant solution. Remember that it is not
technically possible to put a custom cursor on the form at design time; it
might be possible to modify a component to achieve this, but you would still
have the problem of getting the resource into the library. I haven't found
anything in the documentation on how to do this.

You can, however, enter the number 20 (for the above example) in the Cursor
property of the form -- you are not limited to the predefined constants offered
in the drop-down list (crDefault, cdArrow, etc.). So, as long as you remember
to put the LoadCursor() bit in the form activate handler, and the cursor
resource into your executable, it will work in a limited sense via the object
inspector. That way you might be able to spare many individual assignments for
several different controls on the form. I have used the pointing hand cursor
to add a nice effect to the speedbuttons, but remember to adjust the hot-spot
using the image editor!

In the worst case, LoadCursor() will fail and return 0, which is equal to the
default cursor; so -- you don't get your cursor, but you also don't get a GPF!

--
John Reid <jr...@iol.ie> -- "May you be in the debugger half an hour before
the system knows it's crashed!"
-- slightly more modern Irish proverb.

Ray Lischner

unread,
Jun 22, 1995, 3:00:00 AM6/22/95
to
dav...@bruce.cs.monash.edu.au (Andrew Davison) wrote:

>I have the same problem (except that I'm using the resourse workshop to
>edit the default .res file...*shrug*)

Delphi rewrites the resource file that has the same name as the source
file. Any changes you make to it will be lost. You must use a
different file name.
--
Ray Lischner (li...@tempest-sw.com)
Tempest Software


Andy McFarland

unread,
Jun 24, 1995, 3:00:00 AM6/24/95
to
Andrew Davison (dav...@bruce.cs.monash.edu.au) wrote:
: Andrew Crouch (acr...@dmu.ac.uk) wrote:
: : I am trying to add a custom cursor to a Delphi application. I've done
: : everything it says in the help file but I can't get it to work.

: You should look at the value returned from LoadCursor... I'm getting 0,,


: and don't understand why.

The sample code in the Delphi help on custom cursors is incorrect. It has
1 where you should use hInstance. In the .RES file you should have a
cursor named NEWCURSOR.

Screen.Cursors[crMyCursor] := LoadCursor( hInstance, 'NewCursor' ) ;

Andy

Chris Sexton

unread,
Jun 26, 1995, 3:00:00 AM6/26/95
to
>
> Screen.Cursors[crMyCursor] := LoadCursor( hInstance, 'NewCursor' ) ;
>

Can someone tell me where hInstance comes from. Is it a property on the
Form object or something?

Regards

Chris

--
Chris Sexton
cse...@partridge.attiaa.attistel.co.uk
***

Josha Munnik

unread,
Jun 26, 1995, 3:00:00 AM6/26/95
to cse...@partridge.attiaa.attistel.co.uk
Hi,

hInstance is one of the global variables defined in the system
unit. Should be there somewhere in the help.

Greets, Josha.

Josha Munnik

unread,
Jun 26, 1995, 3:00:00 AM6/26/95
to cse...@partridge.attiaa.attistel.co.uk

Josha J. Munnik

unread,
Jun 26, 1995, 3:00:00 AM6/26/95
to cse...@partridge.attiaa.attistel.co.uk
Hi,

hInstance is a global variable defined in the system unit. Should
be there in the help somewhere (else try component writers help).

HInstance defines the current instance of your program.

Greets, Josha

Ray Lischner

unread,
Jun 28, 1995, 3:00:00 AM6/28/95
to
cse...@partridge.attiaa.attistel.co.uk (Chris Sexton) wrote:

>>
>> Screen.Cursors[crMyCursor] := LoadCursor( hInstance, 'NewCursor' ) ;
>>

>Can someone tell me where hInstance comes from. Is it a property on the
>Form object or something?

It is a global variable in the System unit, so it is automatically
declared in every unit.

0 new messages