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
>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
>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)
I wish I had a solution rather than a problem to add to this
discussion . . .
Jeff Jones
>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.
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.
>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
: 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
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
***
hInstance is one of the global variables defined in the system
unit. Should be there somewhere in the help.
Greets, Josha.
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
>>
>> 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.